linux

Delete lines in a text file that contain a specific string and In-place edits with sed on OS X

To remove the line and print the output to standard out:

sed '/pattern to match/d' ./infile

To directly modify the file:

sed -i '/pattern to match/d' ./infile

To directly modify the file (and create a backup):

sed -i.bak '/pattern to match/d' ./infile

For Mac OS X users:

sed -i '' '/pattern/d' ./infile
sed -i '' 's/oldword/newword/' file1.txt
      ^ note the space

Add a line at the beginning of a file

Etiquetas