Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OFF] Awk et les arguments. (résolu)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
RaX
Apprentice
Apprentice


Joined: 16 Aug 2007
Posts: 166

PostPosted: Fri Nov 27, 2009 1:11 pm    Post subject: [OFF] Awk et les arguments. (résolu) Reply with quote

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
View user's profile Send private message
xaviermiller
Bodhisattva
Bodhisattva


Joined: 23 Jul 2004
Posts: 8708
Location: ~Brussels - Belgique

PostPosted: Fri Nov 27, 2009 2:46 pm    Post subject: Reply with quote

Code:
man awk
?
_________________
Kind regards,
Xavier Miller
Back to top
View user's profile Send private message
RaX
Apprentice
Apprentice


Joined: 16 Aug 2007
Posts: 166

PostPosted: Fri Nov 27, 2009 4:05 pm    Post subject: Reply with quote

Je ni ai pas trouvé mon bonheur.
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Wed Dec 02, 2009 11:05 am    Post subject: Reply with quote

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
View user's profile Send private message
RaX
Apprentice
Apprentice


Joined: 16 Aug 2007
Posts: 166

PostPosted: Thu Dec 03, 2009 11:09 am    Post subject: Reply with quote

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
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Thu Dec 03, 2009 12:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Bapt
Veteran
Veteran


Joined: 14 Apr 2003
Posts: 1152
Location: Paris

PostPosted: Thu Dec 03, 2009 1:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
RaX
Apprentice
Apprentice


Joined: 16 Aug 2007
Posts: 166

PostPosted: Thu Dec 03, 2009 6:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
kwenspc
Advocate
Advocate


Joined: 21 Sep 2003
Posts: 4954

PostPosted: Thu Dec 03, 2009 6:13 pm    Post subject: Reply with quote

man awk sinon :wink:
Back to top
View user's profile Send private message
RaX
Apprentice
Apprentice


Joined: 16 Aug 2007
Posts: 166

PostPosted: Thu Dec 03, 2009 6:19 pm    Post subject: Reply with quote

kwenspc wrote:
man awk sinon :wink:


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
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Fri Dec 04, 2009 6:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum