gpt4 book ai didi

linux - 读取文件后如何从文件中删除行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:02:03 25 4
gpt4 key购买 nike

我有这样的代码 -

     > 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

我只需要在处理后删除这些行

最佳答案

您无法在读取文件时更改文件,因此您需要将要保留的条目输出到新文件(或标准输出),并跳过不需要的条目。然后可以仅使用保留的行进一步处理生成的文件。

关于linux - 读取文件后如何从文件中删除行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4813060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com