Hello All,
I am trying to clean up a poorly looking awk command. I am searching for a way to define a range of positional parameters. I may not be searching for the correct syntax.
Example:
awk ' /14:3*/ {print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' app.log
Is it possible to shorten with a range of some kind:
awk ' /14:3*/ {print $2........$13}' app.log
Thanks for your time.
Jaysunn
clx
February 2, 2010, 10:20am
2
you can use loop.
awk '/14:3*/{for (i=2;i<=13;i++){printf "%s ",i}}END{print "\n"}' app.log
jaysunn
February 2, 2010, 11:01am
3
This gives me:
[root@server jason]# awk '/14:3*/{for (i=2;i<=13;i++){printf "%s ",i}}END{print "\n"}' app.log
2 3 4 5 6 7 8 9 10 11 12 13 2 3 4 5 6 7 8 9 10 11 12 13 2 3 4 5 6 7 8 9 10 11 12 13 2 3 4 5 6 7 8 9 10 11 12 13
How do I specify the positions? I assumed it needs $n.
Thanks for your reply.
Jaysunn
clx
February 2, 2010, 11:08am
4
Sorry, It should be
awk '/14:3*/{for (i=2;i<=13;i++){printf "%s ",$i}}END{print "\n"}' app.log
danmero
February 2, 2010, 11:16am
5
awk '/14:3*/{for (i=x-1;i++<y;){printf $i ((i<y)?FS:RS)}}' x=2 y=13