2011-01-27 61 views
0

我有這樣的代碼 -如何在閱讀文件後刪除文件中的行?

 > for line in `cat file.txt`;do 
    /*if line-1 dosomething-1 */ 
    /*if line-2 dosomething-2 */ 
    /* if line-3 dosomething-3 */ 
    //Parsing 3 lines I would like to remove them from file - how to do that? 
    //Parse - line4 
    //Parse - line5 
    //Parse - line6 
    //now delete above 3 lines again & repeat the process till eof.\ 
    done 

我只需要後刪除線及其加工

+0

如果您可以使用Perl,這個問題的答案可以幫助您:http://stackoverflow.com/questions/4732937/how-do-i-read-a-file-line-by-line-while-modifying -lines-as-needed/4733306#4733306 – eckes 2011-01-27 07:50:05

回答

4

爲你讀它你不能改變一個文件,所以您需要輸出你想保留的條目到一個新的文件(或標準輸出),並跳過你沒有的條目。然後,只有保留的行可以進一步處理生成的文件。

相關問題