• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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: 1107
19
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: 7000
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.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic