2012-10-22 93 views
-1

我需要刪除以符號開頭的所有行|使用shell 我有一個文本文件,其中有一些行以|我需要使用shell刪除以|開頭的所有行在使用shell的文本文件中

示例文件

Example 
Example of txt file 

|I need to remove this 
|I need to remove this too 

刪除它,我是新來的外殼任何一個可以告訴我,我該怎麼做,或者給我一些教程來實現這一目標。

回答

0

ugurarpaci的做法是好的,但根本性的缺陷:

sed '/^|/d' filename 

會產生你想要的輸出,但你不能簡單地重定向迴文件。你可以做幾件事情:

sed '/^|/d' filename > new-file 
sed -i '/^|/d' filename # If your sed supports -i and you don't care 
         # about breaking hard links 
sed '/^|/d' filename > tmp-file && mv tmp-file filename 
相關問題