0
我有一個看起來像這樣的文件:包含在文件中的每一行刪除重複出現的字符串
[hello] - one
[hello] - two
[hello] - three
[hello] - four
我要刪除「[你好] - 」每行,以便它會給我
one
two
three
four
我有一個看起來像這樣的文件:包含在文件中的每一行刪除重複出現的字符串
[hello] - one
[hello] - two
[hello] - three
[hello] - four
我要刪除「[你好] - 」每行,以便它會給我
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
什麼是 「算法」:只打印最後一個字段?從第三場打印?刪除'[你好] - '?意思是,如果你有一句「你好嗎」,你需要打印什麼? – fedorqui