Table des matières
Scripts awk
Une doc sur awk : http://people.cs.uu.nl/piet/docs/nawk/nawk_toc.html
Quelques règles et bout de scripts (cf http://cli.asyd.net/home/filtres/awk)
Syntaxe
Boucle for
ls -l | awk '{
fich=$8;
for (i=9;i<=NF;i++) {fich=fich" "$i};
# on sort le nom du fichier avec ses espaces entre guillemets, puis date;heure;taille
print "\""fich"\";"$6";"$7";"$5
}'
Exemples
Découper un fichier
Découper un fichier avec pleins de VirtualHosts en plusieurs fichiers (un par virtualhost, du nom du ServerName)
awk 'BEGIN {new = 0}
/<VirtualHost/ { new = 1; fout = 0; out="";}
/ServerName/ { fout = $2; print out > fout;new=0;}
{if (new>0) { out = out "\n" $0}}
{if (fout!=0) { print $0 > fout;new=0}}' < tous_les_virtualhosts_confondus.conf
linux/scripts_awk/start.txt · Dernière modification: 20/02/2009 15:38 par daniel


