Solaris SED add delete replace
August 7, 2007 – 8:09 pmTip courtesy of Kyle Reynolds at http://www.camelrichard.org
SED add/ delete/ replace
————————
sed -f <scriptname> <filename> # runs the scripted commands against the <filename>
example:
sed -f deletescript myfile.ldif
sed -f addscript newfile.ldif
or from command line:
sed ‘/<searchstring>/d’ filename
———————————————————————————–
———————————————————————————–
deletescript:
# deletes any line containing <searchstring>
/<searchstring>/d
————————————————————————————
addscript:
# adds the <newline entry> above any line containing <searchstring>
/<searchstring>/i\
<newline entry>
————————————————————————————
addscript:
# adds the <newline entry> beneath any line containing <searchstring>
/<searchstring>/a\
<newline entry>
————————————————————————————
replacescript:
# replaces the <searchstring> with the <newline entry>
/<searchstring>/c\
<newline entry>
————————————————————————————
change every lowercase a, b and c to uppercase
sed ‘y/abc/ABC/’ filename
————————————————————————————
Change every instance of <string> with <newstring>
sed ’s/string/newstring/g’ filename