删除文件的每一行中包含的重复字符串



我有一个看起来像这样的文件:

[hello] - one
[hello] - two
[hello] - three
[hello] - four

我想删除每行中的"[hello] -",这样它就会给我

one
two
three
four

试试这个:

cut <filename> -d" " -f3

我会选择cut,但这里有一些其他选择:

awk

$ awk -F' *- *' '{ print $NF }' << EOF
> [hello] - one
> [hello] - two
> [hello] - three
> [hello] - four
> EOF
one
two
three
four

sed

$ sed 's/^[hello] - //' << EOF
> [hello] - one
> [hello] - two
> [hello] - three
> [hello] - four
> EOF
one
two
three
four

相关内容

  • 没有找到相关文章

最新更新