• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple script question:  RSS feed

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the following file contents with tab delimited information on
each line (the headings are not part of the file but provided for
information only):

FirstName lastNAme Age Salary
john smith 22 11000
simon baba 21 20102
sarah louw 24 12000


The File name is "Stuff.txt"
how can i write the unix command line that would extract all the Age values from the file?

thansk a lot for your help!
 
Peter Rooke
Ranch Hand
Posts: 900
7
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get rid of the first line, containing the column headers and then:
Should work.
- put the contents into newFile.txt

use to show the manual for the cut command.
[ September 04, 2006: Message edited by: Peter Rooke ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As another approach, I tend to use "awk" for this sort of thing:



There are plenty of other ways, too. This is "bread and butter" to unix systems.
 
Brian Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the following to cut out the top line automatically as well:

tail +2 stuff.txt | awk '{print $3}' > newfile.txt

Unix - a million ways to skin a cat!
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Wright:
You can use the following to cut out the top line automatically as well:

tail +2 stuff.txt | awk '{print $3}' > newfile.txt

Unix - a million ways to skin a cat!


If you are using awk, why use tail at all? Hint: 'NR'.
 
Brian Wright
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely true!

My reasoning was as follows:

1) awk can get confusing quickly and the OP is clearly new to Unix

2) Given that the OP is new to Unix, getting the idea across of piping output of one command to another seemed like a good step in their education.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!