Computing.Net > Forums > Unix > awk help

awk help

Reply to Message Icon

Original Message
Name: Bill
Date: July 25, 2002 at 11:48:32 Pacific
Subject: awk help
Comment:

I need to use a counter for some output from an awk command...I have a file with two lines in it and I want the contents of these lines preceded by a number...For example:

1. Blue tube
2. Red stick
etc...

Please help!!


Report Offensive Message For Removal

Response Number 1
Name: Anthony
Date: July 26, 2002 at 04:27:45 Pacific
Subject: awk help
Reply: (edit)

Try:

awk 'i=i+1 {print i " " $0}' i=0 filename


Report Offensive Follow Up For Removal

Response Number 2
Name: Frank
Date: August 13, 2002 at 07:15:12 Pacific
Subject: awk help
Reply: (edit)

or just

awk ' { print FNR,$0 } ' filename

no RISK no fun
Frank


Report Offensive Follow Up For Removal

Response Number 3
Name: Bill
Date: August 19, 2002 at 03:59:21 Pacific
Subject: awk help
Reply: (edit)

The FNR option works well Frank, thanks for the suggestion...Now how do I reference the number that was placed there...In other words, if I ask the user for an input to choose one of two options

For example:
1-Red
2-Blue

How do I associate them choosing option 1 with what I want to do?? There could possibly be 8 lines in the file so there would be 1-8 options...I can't possibly code for this using the case statement unless there is a variable I can reference...

Hope you can help...

Bill Hubbard


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: awk help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software