awk
Kategorie: perl-awk-sed

awk -F":" '{ print $1 $3 }' /etc/passwd
awk -F" " '{ print $1 "-" $3 }' test
awk '{ print NR, ". polozek:" NF, $0 }' test

echo "a:b:c" | awk -F ":" '{ print $1 "-" $3 }'

echo "7:5:3" | awk -F ":" '{ print $1 "-" $3 }'

echo "7:5:3" | awk -F ":" '{ print $1 - $3 > "vysledek1"; print $1 * $3 > "vysledek2"}'


%príznaky šírka presnost typ konverze

echo "1.1234:2:3" | awk '{ printf "A=%8.2f, B=%10ld\n", $1, $2 }'
echo "1.1234:2.1:3" | awk -F ":" '{ printf "A=%-5.3f, B=%-5.1e\n", $1, $2 }'

http://www.ics.muni.cz/zpravodaj/articles/33.html



awk '{ if ($1 > $2) print }' cisla

awk '{ if ($1 > $2+5) print }' cisla
echo "abc de" | awk '{ print length($2) }'

udela zalohy
ls *.txt | awk '{print "mv "$1" "$1".back"}' | sh

remove only files:
ls -l * | grep -v drwx | awk '{print "rm "$9}' | sh

remove only directories
ls -l | grep '^d' | awk '{print "rm -r "$9}' | sh

# smazat všechny zálohy ve všech podadresářích
find -type f -name '*~' -exec rm -vf {} \;




7.3.2007 17:15:19