Thursday, January 14, 2016

Linux: grep, sed

Find a line and append strings

  1. "grep" allows to find lines that contains the string/characters
  2. "sed" allows to append string/characters
$sed '/3696/ s/$/running file.txt'
foo1 3464
foo2 3696 running
foo3 4562
$sed 's/3696/& running/' file.txt
foo1 3464
foo2 3696 running
foo3 4562
P.S. Add the -i option to save the changes back to file.txt

Reference

http://stackoverflow.com/questions/14051883/how-to-append-text-to-a-specific-lines-in-a-file-using-shell-script

No comments:

Post a Comment