• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

simple script question:

 
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 1158
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic