开发者

How to delete lines from file after reading it?

I have a code like this -

     > 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开发者_Python百科 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

I just need to delete the lines after its processed


You can't change a file as you're reading it, so you'll need to output the entries you want to keep to a new file (or stdout), and skip the entries you don't. Then the resulting file can be processed further with only the kept lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜