Awk: Question
Résolu
tlep
Messages postés
596
Date d'inscription
Statut
Membre
Dernière intervention
-
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
lami20j Messages postés 21331 Date d'inscription Statut Modérateur, Contributeur sécurité Dernière intervention -
Bonjour à tous,
j'ai un petit souci avec awk:
#!/bin/bash
a=2
toto="U trunk/site/thierry.php A trunk/site/thierry2.php A trunk/site/thierry3.php"
echo "$toto"|awk '{print $a}'
=> me renvoie toute la chaine "toto", comme si "$a" valait "0".
Comment puis-je mettre une variable dans le {print } de awk ?
Merci pour votre retour :-)
j'ai un petit souci avec awk:
#!/bin/bash
a=2
toto="U trunk/site/thierry.php A trunk/site/thierry2.php A trunk/site/thierry3.php"
echo "$toto"|awk '{print $a}'
=> me renvoie toute la chaine "toto", comme si "$a" valait "0".
Comment puis-je mettre une variable dans le {print } de awk ?
Merci pour votre retour :-)
3 réponses
Non çà marche po.
En fait j'ai trouvé c'était :
echo "$toto"|awk "{print \$"$a"}"
Pour une fois j'ai la réponse avant jipicy lol :-))
En fait j'ai trouvé c'était :
echo "$toto"|awk "{print \$"$a"}"
Pour une fois j'ai la réponse avant jipicy lol :-))
Salut,
Ton backslash est inutile ;-))
Ton backslash est inutile ;-))
lami20j@debian:~$ a=2 lami20j@debian:~$ toto="U trunk/site/thierry.php A trunk/site/thierry2.php A trunk/site/thierry3.php" lami20j@debian:~$ echo "$toto"|awk "{print \$"$a"}" trunk/site/thierry.php lami20j@debian:~$ echo "$toto"|awk "{print $"$a"}" trunk/site/thierry.php