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

标签 linux bash

我有这样的代码 -

     > 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/

相关文章:

android - 适用于 Linux 上的 Android 的 Poco C++

bash - 变量在范围内的 for 循环将不起作用

bash - 如何将进度条添加到 somearchive.tar.xz 提取

linux - Mobaxterm 终端中的 Git 凭据

linux - 找不到 IPCCLEAN 命令

java - 使用Maven程序集插件设置特定文件的Linux文件权限

regex - 为什么 grep 无法在 bash 中匹配字符串 "-n"和 "-e"?

bash - 如何根据从第二个文件获取的值范围排除文件中的行

linux - 为什么 Bash 评估我存储在先前变量中的变量扩展?

c++ - 世界语言联盟。 Visual Studio 2015 中的空输出文件