View previous topic :: View next topic |
Author |
Message |
RaX Apprentice
Joined: 16 Aug 2007 Posts: 166
|
Posted: Fri Nov 27, 2009 1:11 pm Post subject: [OFF] Awk et les arguments. (résolu) |
|
|
Bonjour à tous.
Juste une petite question avec awk. J'ai besoin de lui faire passer des variables mais sans utiliser de pipe. Exemple:
Code: |
I=1
echo $I | awk '{printf "%02d\n", $1}'
|
Avez vous une idée ?
Merci.
Last edited by RaX on Tue Dec 15, 2009 8:31 pm; edited 1 time in total |
|
Back to top |
|
|
xaviermiller Bodhisattva
Joined: 23 Jul 2004 Posts: 8708 Location: ~Brussels - Belgique
|
Posted: Fri Nov 27, 2009 2:46 pm Post subject: |
|
|
? _________________ Kind regards,
Xavier Miller |
|
Back to top |
|
|
RaX Apprentice
Joined: 16 Aug 2007 Posts: 166
|
Posted: Fri Nov 27, 2009 4:05 pm Post subject: |
|
|
Je ni ai pas trouvé mon bonheur. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Wed Dec 02, 2009 11:05 am Post subject: |
|
|
Tu n'as pas expliqué précisément ce que tu veux faire?
Quels sont les arguments à faire passer? comment pourquoi? Et après on verra! _________________ The End of the Internet! |
|
Back to top |
|
|
RaX Apprentice
Joined: 16 Aug 2007 Posts: 166
|
Posted: Thu Dec 03, 2009 11:09 am Post subject: |
|
|
Salut truc.
C'est une question général sur awk, pour la pauser différemment comment pourrait-on faire pour faire ceci:
$ Y=2
$ echo $Y | awk '{printf "%04d\n", $1} '
Sans utiliser de pipe et en utilisant awk. |
|
Back to top |
|
|
Temet Advocate
Joined: 14 Mar 2006 Posts: 2586 Location: 92
|
Posted: Thu Dec 03, 2009 12:09 pm Post subject: |
|
|
Pas sûr que tu puisses puisque awk sert à manipuler des fichiers!
Si tu ne veux pas piper, t'es obligé de créer un fichier et d'utiliser awk dessus ensuite (enfin je pense). _________________ Full Gentoo powered. |
|
Back to top |
|
|
Bapt Veteran
Joined: 14 Apr 2003 Posts: 1152 Location: Paris
|
Posted: Thu Dec 03, 2009 1:45 pm Post subject: |
|
|
tout simple tu as même plusieurs choix :
Code: | awk -v y=$Y 'BEGIN{printf "%04d\n", y}' |
Code: | awk 'BEGIN{printf "%04d\n", '$Y'}' |
par exemple |
|
Back to top |
|
|
RaX Apprentice
Joined: 16 Aug 2007 Posts: 166
|
Posted: Thu Dec 03, 2009 6:11 pm Post subject: |
|
|
Tout comme Temet je pensais que c'était impossible, j'ai quand même tenter la question et miracle Bapt a poster les quelques lignes qu'il me fallait.
Merci à tous, merci Bapt.
Last edited by RaX on Thu Dec 03, 2009 6:17 pm; edited 1 time in total |
|
Back to top |
|
|
kwenspc Advocate
Joined: 21 Sep 2003 Posts: 4954
|
Posted: Thu Dec 03, 2009 6:13 pm Post subject: |
|
|
man awk sinon |
|
Back to top |
|
|
RaX Apprentice
Joined: 16 Aug 2007 Posts: 166
|
Posted: Thu Dec 03, 2009 6:19 pm Post subject: |
|
|
kwenspc wrote: | man awk sinon |
Merci du conseil mais si je pose la question c'est que je ne suis pas arrivé a me débrouiller avec le manuel. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Fri Dec 04, 2009 6:49 am Post subject: |
|
|
Bapt wrote: | tout simple tu as même plusieurs choix :
Code: | awk -v y=$Y 'BEGIN{printf "%04d\n", y}' |
Code: | awk 'BEGIN{printf "%04d\n", '$Y'}' |
par exemple |
C'est à ça que je pensais, mais le monsieur n'était pas clair! Bref, dans le deuxième exemple, tu peux t'éviter des problèmes en quotant comme il se doit si ton argument est une chaine de caractère
Code: | awk 'BEGIN { printf "%4s\n", "'"$Y"'" }' |
dans l'ordre nous avons printf "%4s\n", " ' "$Y" ' " }' (les espaces sont juste là pour que tu vois) _________________ The End of the Internet! |
|
Back to top |
|
|
|