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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how many columns are there in text file ??

Status
Not open for further replies.

samirm

Technical User
May 12, 2003
80
US
Hi,

We have received a file with many no. of columns.
Is there any command, so that I can extract the desired fields from that file ?? How can I count the total no. of columns in that file ?

thanks ...

Sam
 
You can use awk which has a built-in variable called NF which holds the Number of Fields (i.e. columns)...

[tt]awk '{print NF}' file1[/tt]

...will print the number of fields for every line in the file, so...

[tt]awk '{print NF}' file1 | uniq [/tt]

...should just give one result if all lines have the same number of fields.
 
Hi ,

Use the same awk to extract the column you want to extract.

E.g.

awk '{print $1}' file1
will extract you the first column, $2 will second, $3 will third and so on.

Cheers
 
thanks to all !!
It solved my purpose ...

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top