25 August 2017

Sed cheat sheet

Sometimes we need to clean-up a file (ie: log prod file).

(or gsed for gnu-sed in macosx

* delete a match and backup of original file:

sed -i.bak '/<ConnectionEnv.cleanup, jconn=oracle.jdbc.driver.T4CConnection/d' ./infile

sed -i.bak '/INFO: true/d' ./infile

gsed -i.bak '/INFORMACIÓN: true> /d' ./infile


* delete two lines and the match string

gsed -i -e '/match1/,+2d'

* delete one line and the match string

gsed -i -e '/OPTIONS/,+1d' *uml*.puml

* execute more than one command in sed (use -e flag)

sed -i -e 's/File//g' -e 's/MINvac.pdb//g'

* recursive find and replace

find . -type f -print0 | xargs -0 sed -i 's/MYSQL_USER/MYSQL_ROOT_USER/g'

* no lookups by default

use: -E o -r ( -E, -r, --regexp-extended )


No comments :

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.