說我有一個行數開始foobar
如何將'foobar'開頭的所有行移動到文件末尾?
一個劇本,我想所有的線移動到文檔的末尾,同時保持它們的順序
例如從去:
# There's a Polar Bear
# In our Frigidaire--
foobar['brangelina'] <- 2
# He likes it 'cause it's cold in there.
# With his seat in the meat
foobar['billybob'] <- 1
# And his face in the fish
到
# There's a Polar Bear
# In our Frigidaire--
# He likes it 'cause it's cold in there.
# With his seat in the meat
# And his face in the fish
foobar['brangelina'] <- 2
foobar['billybob'] <- 1
這是據我已經得到了:
grep foobar file.txt > newfile.txt
sed -i 's/foobar//g' foo.txt
cat newfile.txt > foo.txt
提示:輸出文件就是所有的行不foobar的開始,接着用foobar的開頭的所有行。兩個grep命令。 – Amnon
@Amnon謝謝你指出。有道理,但我仍然不知道如何說bash – Abe
@Amnon'-v'得到了它 – Abe