Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extarcting a column from records of a file

Status
Not open for further replies.

hello99hello

Programmer
Jul 29, 2004
50
0
0
CA
Hello All,

I have a file (levln_ac_in.txt) with the following sample record format:
200159,,,3/21/1996,3/22/1996,,VACATION,VAC.TAKEN OTHER GRPS,,15,,,0

I am trying to extract the contents of the 8th column of each record of file levln_ac_in.txt and put it in an output file levln_dt_in.txt

Here is my effort:
#!/bin/sh

#extract column 2 from file
awk -v c=8 'NR==r { print $c }' levln_ac_in.txt > levln_dt_in.txt

my output file should contain the following format sample records:
VAC.TAKEN OTHER GRPS

However the output file is retunring zero, please help.
 
Code:
nawk -F, -v c=8 '{print $c}' levln_ac_in.txt > levln_dt_in.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanx,

I was able to ommit the n and use the following:

awk -F, -v c=8 '{print $c}' levln_ac_in.txt > levln_dt_in.txt

It works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top