Register
It is currently Sun Dec 21, 2014 2:45 am

extract column based on header


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Sun May 16, 2010 2:15 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi everyone,
I found this nifty script for extracting a column from a tab sepparated file based on the header title.
I would like to customize it to a shell script that takes a first parameter the filename, and second parameter
the header you want to extract. The filename is easiest, but I don't know how to do it for the Headertitle

#!/usr/bin/env bash
awk 'NR==1{for(i=1;i<=NF;i++)if($i~/HEADERTITLE/)f[n++]=i}{for(i=0;i<n;i++)printf"%s%s",i?" ":"",$f[i];print""}' $1

Ted.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP