Retrieving values from tab-delimited file in unix script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Retrieving values from tab-delimited file in unix script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-27-2009
akashtcs akashtcs is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 17 August 2010, 7:45 AM EDT
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Retrieving values from tab-delimited file in unix script

Hi

I am trying to retrieve values from a tab-delimited file.I am using


Code:
while read record

value=`echo $record | cut -f12`

done

Where 12 is the column no i want retieve and record is one line of the file.
But it is returning the full record.
Plz help
Sponsored Links
    #2  
Old 08-27-2009
kd09714 kd09714 is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 January 2012, 4:51 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
see man page for awk

try to use awk with the file .
ex : awk '{ print $12 }' file_name
Sponsored Links
    #3  
Old 08-27-2009
akashtcs akashtcs is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 17 August 2010, 7:45 AM EDT
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

I tried with a test file.It worked perfectly fine.
But for the file that I have to process,it is not working.
This file has been created from an excel file by converting the excel to a tab-delimited windows file.

Any idea why this file is not getting processed?

Thanks
    #4  
Old 08-27-2009
Festus Hagen Festus Hagen is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 31 December 2013, 1:03 AM EST
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
I believe you need to run it through 'dos2unix'!

-Enjoy
fh : )_~
Sponsored Links
    #5  
Old 08-27-2009
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
You need to tell cut that the delimiter is a tab and to put quotes round $record.


Code:
#!/bin/ksh
TAB=`echo "\0011\c"`
cat tab_delimited_file | while read record
do
        value=`echo "${record}" | cut -f12 -d"${TAB}"`
        echo "${value}"
done

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with retrieving values from properties file sailaja_80 Shell Programming and Scripting 2 08-21-2009 03:06 PM
convert a pipe delimited file to a':" delimited file priyanka3006 Shell Programming and Scripting 6 05-26-2009 10:53 AM
splitting a pipe delimited file in unix ddedic Shell Programming and Scripting 4 03-20-2007 01:16 AM
how to extract a tilde delimited file in unix trichyselva Shell Programming and Scripting 12 03-05-2007 11:19 PM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 08:24 AM



All times are GMT -4. The time now is 10:11 PM.