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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read the column and print the values under that column
# 1  
Old 03-28-2008
MySQL how to read the column and print the values under that column

hi allSmilie,

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..Smilie
# 2  
Old 03-28-2008
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  
Old 03-28-2008
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  
Old 03-28-2008
Hope this helps

Code:
awk -F"," '/date/{}{print $(NF-1)}' testfile

Please ignore this post
# 5  
Old 03-28-2008
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  
Old 03-28-2008
Meanwhile i was trying...heres one approach...
but i guess ...not a gd one Smilie


Code:
awk -F"|" '{ 
	    split ($0,a,",")
	    for (i=0 ;i<=NF;i++) 
		{
		if (a[i] == "date")
		val =i 
		}
	   } { print $val}'

This User Gave Thanks to Shivdatta For This Post:
# 7  
Old 03-28-2008
Thanks 2 all Smilie , its working fine...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

2. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

3. Shell Programming and Scripting

Read 4th column and print those many rows

Hi, My input file chr1 3217769 3217789 2952725-5 255 + chr1 3260455 3260475 2434087-6 255 - My desired output chr1 3217769 3217789 2952725-1 255 + chr1 3217769 3217789 2952725-2 255 + chr1 3217769 3217789 2952725-3 255 + chr1 3217769 3217789 2952725-4 255 +... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Read column values from previous and next line using awk

Hi, I have a csv file which contains data that looks something like this: Key1 Key2 Key3 New_Key1 New_Key2 New_Key3 102 30 0 - - - 102 40 1 30 40 50 102 50 2 40 50 ... (4 Replies)
Discussion started by: Nishi_Licious
4 Replies

7. Shell Programming and Scripting

Print rows in reverse order if values decrease along the column

Hi, Guys. Please help me to find solution to this problem using shell scripting. I have an INPUT file with 4 columns separated by tab. Each block of records is separated by ----- ----- Sample1 5402 6680 Pattern01 Sample2 2216 2368 Pattern02... (6 Replies)
Discussion started by: sam_2921
6 Replies

8. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

9. Shell Programming and Scripting

read column values one after another

hi, Can some one help me how to retrieve column values row by row My requirement is like below : I have a text file having comma seperated values of these records . OName OType SrcDB Sschema targetdb TSchema Load Dataype processY/N aa Table a e i m Y db2 y aa index b c d e N sql N ... (4 Replies)
Discussion started by: sailaja_80
4 Replies

10. Shell Programming and Scripting

Print column names along with values from SQL

Hi, Can anyone tell me how to print the column name anong with the value from the table in shell script e.g #!/bin/ksh var=`sqlplus scott/tiger << -e set heading off feedback off select * from emp; quit; e` echo $var My output should be; ... (5 Replies)
Discussion started by: thana
5 Replies
Login or Register to Ask a Question