The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-02-2008 02:21 AM
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 09:57 AM
Need help with switching field/column values sonyd8 Shell Programming and Scripting 7 02-13-2008 01:10 AM
replace a column values with the first value in column sumeet UNIX for Advanced & Expert Users 3 02-06-2007 01:13 PM
Capturing the values of column in one parameter mgirinath Shell Programming and Scripting 5 06-14-2006 01:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2008
gemini106 gemini106 is offline
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..
  #2 (permalink)  
Old 03-28-2008
Shivdatta Shivdatta is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 73
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
  #3 (permalink)  
Old 03-28-2008
gemini106 gemini106 is offline
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,
  #4 (permalink)  
Old 03-28-2008
Shivdatta Shivdatta is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 73
Hope this helps

Code:

awk -F"," '/date/{}{print $(NF-1)}' testfile
Please ignore this post
  #5 (permalink)  
Old 03-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 }'
  #6 (permalink)  
Old 03-28-2008
Shivdatta Shivdatta is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 73
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}'
  #7 (permalink)  
Old 03-28-2008
gemini106 gemini106 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 8
Thanks 2 all , its working fine...
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0