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 one liner,但 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屋!
查看全文