Define Positional Parameter Range Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Define Positional Parameter Range Awk
# 1  
Old 02-02-2010
Define Positional Parameter Range Awk

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:

Code:
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:

Code:
awk ' /14:3*/  {print $2........$13}' app.log

Thanks for your time.

Jaysunn

Last edited by jaysunn; 02-02-2010 at 10:58 AM.. Reason: Fixed command error.
# 2  
Old 02-02-2010
you can use loop.
Code:
awk '/14:3*/{for (i=2;i<=13;i++){printf "%s ",i}}END{print "\n"}' app.log

# 3  
Old 02-02-2010
This gives me:
Code:
[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
# 4  
Old 02-02-2010
Sorry, It should be

Code:
awk '/14:3*/{for (i=2;i<=13;i++){printf "%s ",$i}}END{print "\n"}' app.log

# 5  
Old 02-02-2010
Code:
awk '/14:3*/{for (i=x-1;i++<y;){printf $i ((i<y)?FS:RS)}}' x=2 y=13

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Increment with awk - how to define start value

Hello, I am running under ubuntu18.04 My question is about awk. inputfile 0wo010011oasasds sdjhsdjh=, u12812888 8jsjkahsjajnsanakn akjskjskj=, suhuhuhwx kskkxmsnnxsnjxsnjxsnjjnjjdi=, 22878ssssss Below code adds consecutive numbers when string = is found run_code: awk -F'=' -v OFS='='... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Extracting unknown positional parameter in Bourne shell

I have a variable that contains the number of a positional parameter. There is no way of knowing what number this may be, although it is guaranteed to correspond with a valid parameter. In BASH I could just use ${@} to extract that argument. But in a Bourne shell the best I can come up with is... (3 Replies)
Discussion started by: mij
3 Replies

3. Shell Programming and Scripting

Positional parameter passing

Hi All, When passing parameters to a sheel script, the parameters are referenced by their positions such as $1 for first parameter, $2 for second parameter. these positional values can only have values ranging from $0-$9 (0,1,2,3...9). I have a shell script meant to accept 20 parameters. for... (3 Replies)
Discussion started by: ogologoma
3 Replies

4. UNIX for Dummies Questions & Answers

Simple awk script for positional replacement in text?

I have a string of letters. (They happen to be DNA, not that it's relevant to the question.) For analysis purposes, I need to replace the information at some of the sites. I need to do this based on their position, not the information in that position. I also need to ignore differences at other... (10 Replies)
Discussion started by: JFS
10 Replies

5. Shell Programming and Scripting

AWK: replace single positional character given variables

I already have accomplished this task using sed and arrays, but since I get the variable using awk, I figured I'd ask this question and maybe I can get a cleaner solution using strictly awk.. I just can't quite grasp it in awk. Story: I'm automating the (re)configuration of network interfaces,... (3 Replies)
Discussion started by: System Shock
3 Replies

6. UNIX for Advanced & Expert Users

dhcpd - range parameter

Hi All, I'm curious about what this community would think about this portion of a dhcpd.conf file: subnet 192.168.1.0 netmask 255.255.255.0 { ... ...other parameters/options... ... range 192.168.1.3 192.168.1.253 range 172.16.0.2 172.16.0.50 } I tested this and dhcpd did not barf... (2 Replies)
Discussion started by: Keene44
2 Replies

7. IP Networking

dhcpd - range parameter

Hi All, I'm curious about what this community would think about this portion of a dhcpd.conf file: subnet 192.168.1.0 netmask 255.255.255.0 { ... ...other parameters/options... ... range 192.168.1.3 192.168.1.253 range 172.16.0.2 172.16.0.50 } I tested this and dhcpd did not barf... (1 Reply)
Discussion started by: Keene44
1 Replies

8. Linux

dhcpd - range parameter

Hi All, I'm curious about what this community would think about this portion of a dhcpd.conf file: subnet 192.168.1.0 netmask 255.255.255.0 { ... ...other parameters/options... ... range 192.168.1.3 192.168.1.253 range 172.16.0.2 172.16.0.50 } I tested this and... (1 Reply)
Discussion started by: Keene44
1 Replies

9. Shell Programming and Scripting

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies

10. AIX

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies
Login or Register to Ask a Question