Tuesday, 8 July 2008

Useful one-liners

Some useful one liners for bash scripting....

Removing the lines that start with #
cat file.conf | sed '/ *#/d; /^ *$/d'
Replacing text within configuration files (replace yes with no when PRELINKING)
sed '/PRELINKING/s/yes/no/g' /etc/sysconfig/prelink > /etc/sysconfig/prelink.new 
awk '/PRELINKING/{gsub(/yes/, "no")};{print}' /etc/sysconfig/prelink > /etc/sysconfig/prelink.new
Delete all blank lines on a file
sed '/^$/d' filename
Number lines (except blank ones)
awk 'NF{$0=++a " :" $0};{print}' filename


to be updated...


No comments:

Post a Comment