Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete all lines that begin with "string" in unix sh?

Tags:

file

unix

sh

sed

How do you delete all lines in a file that begin with "string" in sh? I was thinking about using the sed command.

like image 598
t3hcakeman Avatar asked Nov 09 '11 16:11

t3hcakeman


People also ask

How do you remove certain lines from Unix file?

To Remove the lines from the source file itself, use the -i option with sed command. If you dont wish to delete the lines from the original source file you can redirect the output of the sed command to another file.

How do you remove multiple lines in Unix?

Deleting Multiple LinesPress the Esc key to go to normal mode. Place the cursor on the first line you want to delete. Type 5dd and hit Enter to delete the next five lines.

How do I delete a range of lines in Linux?

The sed command can remove the lines of any range. For this, we just have to enter 'minimum' and 'maximum' line numbers. In this example, we will remove the lines ranging from 4 to 7 numbers. After removing these ranges of lines, our file will look like this.


1 Answers

grep -v '^string' yourfile.txt > stripped.txt 
like image 149
Marc B Avatar answered Sep 22 '22 09:09

Marc B