我需要用 grep 修剪一些文本,我尝试了各种其他方法但运气不佳,例如:
C:\Users\Admin\Documents\report2011.docx: My Report 2011
C:\Users\Admin\Documents\newposter.docx: Dinner Party Poster 08
如何修剪文本文件,修剪“:”及其后的所有字符。
例如所以输出会是这样的:
C:\Users\Admin\Documents\report2011.docx
C:\Users\Admin\Documents\newposter.docx
最佳答案
使用 awk?
awk -F: '{print $1':'$2}' inputFile > outFile
你可以使用 grep (注意 -o 只返回匹配的文本)
grep -oe "^C:[^:]" inputFile > outFile
关于linux - 如何使用 grep 修剪特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6284256/