2011-01-27 64 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

为你读它你不能改变一个文件,所以您需要输出你想保留的条目到一个新的文件(或标准输出),并跳过你没有的条目。然后,只有保留的行可以进一步处理生成的文件。

相关问题