bash,在冒号之前提取字符串 [英] bash, extract string before a colon
本文介绍了bash,在冒号之前提取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的文件中包含这样的行
If I have a file with rows like this
/some/random/file.csv:some string
/some/random/file2.csv:some string2
是否有某种方法可以获取仅包含冒号前一部分的文件,例如
Is there some way to get a file that only has the first part before the colon, e.g.
/some/random/file.csv
/some/random/file2.csv
我宁愿只使用bash一种衬板,但是perl或python也是可以的.
I would prefer to just use a bash one liner, but perl or python is also ok.
推荐答案
cut -d: -f1
或
awk -F: '{print $1}'
或
sed 's/:.*//'
这篇关于bash,在冒号之前提取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文