2013-04-04 306 views

回答

2

刪除線:

隨着grep

http://lowfatlinux.com/linux-grep.html

The grep command selects and prints lines from a file (or a bunch of files) that match a pattern.

我認爲你可以做這樣的事情:

grep -v '^[\#\&\*]' yourFile.txt > output.txt 

您還可以使用sed做同樣的事情(檢查http://lowfatlinux.com/linux-sed.html):

sed '^[\#\&\*]/d' yourFile.txt > output.txt 

它是由你來決定


過濾行:

我的錯誤,我知道你想刪除這些行。但是,如果你想「刪除」所有其他線路(或過濾起始於指定字符的各線),然後grep是要走的路:

grep '^[\#\&\*]' yourFile.txt > output.txt 
+0

它不工作。 – user1844845 2013-04-04 22:54:10

+0

先用單個表達式嘗試:'grep -v'^#'yourFile> output'。您可能需要轉義字符:'grep -v'^ \#'yourFile> output' – Barranka 2013-04-04 22:56:16

+0

但是我需要保持行以&或*或#開頭,而不是刪除它們。我想刪除所有其他行。 – user1844845 2013-04-04 23:06:43

2
egrep '^(&|#|\*)' input.txt > output.txt 
+0

它不起作用。 – user1844845 2013-04-04 22:54:37

+0

你能更具體嗎?你得到的輸出是什麼? – 2013-04-04 22:57:12

+0

Erro that |不是例外。 – user1844845 2013-04-04 22:59:59

0
sed -n '/^[#&*].*/p' input.txt > output.txt 

這應該工作。

sed -ni '/^[#&*].*/p' input.txt 

這個人會直接編輯輸入文件,要小心+

相關問題