user2399453
user2399453

Reputation: 3081

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. 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. How can I do this with sed or some other unix cmd line?

Upvotes: 2

Views: 1030

Answers (2)

Ed Morton
Ed Morton

Reputation: 203189

sed 's/^Done [0-9]*$//' infile

Upvotes: 4

Arif Burhan
Arif Burhan

Reputation: 505

Use sed: sed 's/[0-9]*/\n/' filename.txt >newfile.txt

Use whatever your regexp was after s/ and add a g after final / if you are expecting more than one integer per line.

Upvotes: 0

Related Questions