The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace the column values. charandevu Shell Programming and Scripting 6 04-01-2008 11:21 PM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 06:57 AM
Need help with switching field/column values sonyd8 Shell Programming and Scripting 7 02-12-2008 10:10 PM
replace a column values with the first value in column sumeet UNIX for Advanced & Expert Users 3 02-06-2007 10:13 AM
Capturing the values of column in one parameter mgirinath Shell Programming and Scripting 5 06-14-2006 10:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 8
Thumbs up how to read the column and print the values under that column

hi all,

how to read the column and print the values under that column ...??

file1 have something like this

cat file1
=======
column1, column2,date,column3,column4.....
1, 23 , 12/02/2008,......
2, 45, 14/05/2008,.....
3, 56, 16/03/2008,.....


cat file2
=======
column1,date,column3,column4.....
1,12/02/2008, 34,......
2,14/05/2008,56, .....
3,16/03/2008,78......

i need output like this

cat file1
=====
date
12/02/2008
14/05/2008
16/03/2008

cat file2
=====
date
12/02/2008
14/05/2008
16/03/2008


only date filed column values ...

pls help ...

thx in advance..
Reply With Quote
Forum Sponsor
  #2  
Old 03-28-2008
Registered User
 

Join Date: Mar 2006
Location: Mumbai
Posts: 67
Code:
awk -F"," '{print $3}'file1

Similarly for file2...

awk -F"," '{print $2}'file2

The o/p will appear on the screen....redirect to a file as per ur requirment
Reply With Quote
  #3  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 8
thx for respond,
this i knew , but i need a script to handle that column date

date column maybe $1 , $2 ,$3, $4.....

thx,
Reply With Quote
  #4  
Old 03-28-2008
Registered User
 

Join Date: Mar 2006
Location: Mumbai
Posts: 67
Hope this helps

Code:
awk -F"," '/date/{}{print $(NF-1)}' testfile
Please ignore this post
Reply With Quote
  #5  
Old 03-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Actually you are on the right track there.

Code:
awk -F, 'NR==1{for (i=0; i<=NF; i++) { if ($i == "date") break; } }
{ print $i }'
Reply With Quote
  #6  
Old 03-28-2008
Registered User
 

Join Date: Mar 2006
Location: Mumbai
Posts: 67
Meanwhile i was trying...heres one approach...
but i guess ...not a gd one


Code:
awk -F"|" '{ 
	    split ($0,a,",")
	    for (i=0 ;i<=NF;i++) 
		{
		if (a[i] == "date")
		val =i 
		}
	   } { print $val}'
Reply With Quote
  #7  
Old 03-28-2008
Registered User
 

Join Date: Mar 2008
Posts: 8
Thanks 2 all , its working fine...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0