2014-02-25 32 views
0

我有一個看起來像這樣的文件:包含在文件中的每一行刪除重複出現的字符串

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

我要刪除「[你好] - 」每行,以便它會給我

one 
two 
three 
four 
+0

什麼是 「算法」:只打印最後一個字段?從第三場打印?刪除'[你好] - '?意思是,如果你有一句「你好嗎」,你需要打印什麼? – fedorqui

回答

1

試試這個:

cut <filename> -d" " -f3

0

我會去與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 
相關問題