Sed-删除字符串前的x个字符 [英] Sed - Delete x numbers of characters before a string
本文介绍了Sed-删除字符串前的x个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个txt文件,我想删除特定字符串前的x个字符
I have a txt file and I want to delete x number of characters before a specific string
示例:
52.451878252 foo 845.851878212 foo
98.444854655 foo 458.344854656 foo
我想删除字符串'foo'之前的8个字符以获取此信息:
I want to delete 8 characters before the string ' foo' in order to get this :
52.45 foo 845.66 foo
98.44 foo 458.66 foo
我应该如何使用sed命令(或其他方法)?
How should I do with the sed command (or something else) ?
谢谢:)
推荐答案
在这里:
sed -e 's/........foo/ foo/g' file.txt
或等效地:
sed -e 's/.\{8\}foo/ foo/g' file.txt
甚至:
sed -e 's/.\{8\}\(foo\)/ \1/g' file.txt
或者采用另一种方法,为您的样本提供相同的输出:
Or a different approach, with the same output for your sample:
sed -e 's/[0-9]\{7\} / /g' file.txt
这篇关于Sed-删除字符串前的x个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文