Posts

Showing posts with the label sed

Common Commands for Sed on FreeBSD

Replace string: % sed -i .bak 's/original/new/g' test.txt      -i Edit files in-place, saving backups with the specified extension(here it is .bak ).   Replace the comments of C language: % sed 's/\(\/\*\).*\(\*\/\)//g' test.c Delete the line contains pattern string: % sed -i .bak '/pattern_string/d'  file.txt Add new line after pattern string: % sed -E 's/(pattern_string)/\1\nnew line/' file.txt -E Interpret regular expressions as extended (modern) regular expressions rather    than basic regular expressions (BRE's). \1 Represent pattern string. Escape single quote: % sed 's/ones/one\x27s/' And string ones thing will become one's thing . Copy specific lines in a file to another file: copy lines 10 to 15 of file1.txt into file2.txt . % sed -n '10,15p' file1.txt > file2.txt Non-greedy matching for ssed (super sed). The content of file test.txt was as follows: ssABteAstACoABnnACss   Non-greed matching command as follows: ...