Wiki‎ > ‎

Bash commands usage examples: sed, awk etc.

posted Aug 2, 2016, 4:49 PM by Danny Xu   [ updated Oct 8, 2016, 11:10 PM ]

# add text to the first line of a file
sed  -i '1i text' filename
#delete blank lines
sed '/^$/d

#delete spaces in a line
sed 's/^[\t]*//;s/[ \t]*$//'

#process scanmem output list
cat out|grep heap|grep 8,|awk '{print $1}'| sed 's/\[//'|sed 's/\]/,/'|sed 's/^[\t]*//;s/[ \t]*$//'|transpose.awk |tr -d ' '

#ssh check n001-n999 cluster nodes
sh -c 'for i in $(seq -w 001 999); do echo "===n$i==="; ssh n$i "df -h"; done'