Thursday, 23 June 2011

lovely sed

If you dont love sed you are not an admin. (non negotiable)

Useful notes:

Lets say we have a file named "files" that has names of rpm packages in them

Removing first character from each filename/string
cat files |sed 's/.\(.*\)/\1/'

Removing last character from each filename/string
cat files |sed 's/\(.*\)./\1/'

Removing the last three characters from every filename
cat files | sed 's/\(.*\).../\1/'

Replacing extensions  from each filename/string
cat files | sed 's/\(.*\).../\1tar/' 

This is an addition to the original post.. I found some old notes on a txt file so...

Clean chars from files
sed -i 's/#//' *
sed -i '/^$/d'
sed -i '/^M/d'


Print file in reverse
cat | filename sed '1!G;h;$!d'


Want even more? Check this and this



:)


No comments:

Post a Comment