[英]Replace a line matching a pattern in a file with blank line
I have a file with a few tens of thousands of csv lines with some lines that are like "Done nnn" where nnn is a variable number. 我有一个包含几万条csv行的文件,其中有些行类似于“ Done nnn”,其中nnn是一个可变数字。 I want to replace these lines with a blank line.
我想将这些行替换为空白行。 I can rip them out completely if I do a grep -v "Done" filename.txt but I want to replace the "Done" lines with a new line.
如果我执行grep -v“ Done” filename.txt,但是可以将新行替换为“ Done”行,则可以完全将其删除。 How can I do this with sed or some other unix cmd line?
我该如何用sed或其他unix cmd行呢?
sed 's/^Done [0-9]*$//' infile
Use sed: sed 's/[0-9]*/\\n/' filename.txt >newfile.txt
使用sed:
sed 's/[0-9]*/\\n/' filename.txt >newfile.txt
Use whatever your regexp was after s/ and add ag after final / if you are expecting more than one integer per line. 如果期望每行有多个整数,请使用s /之后的正则表达式,并在final /后添加ag。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.