How to read particular line in file from specific column? | 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.

How to read particular line in file from specific column?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-28-2013
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
How to read particular line in file from specific column?

Hi...friends....

I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header

I attached sample file..those who know please help...
my input


Code:
ST_DATE    LATITUDE    LONGITUDE
05 Aug 1988 07:10:00 AM    9.983    68.033
05 Aug 1988 07:10:00 AM    9.983    68.033
05 Aug 1988 07:10:00 AM    9.983    68.033

need of output is like this


Code:
filename    date    time    lat    long
myfile.txt    05/08/98    07:10:00    9.983    68.033

Attached Files
File Type: txt myfile.txt (139 Bytes, 12 views)
File Type: txt output.txt (71 Bytes, 11 views)
Sponsored Links
    #2  
Old 01-28-2013
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts

Code:
awk 'FNR == 2 {print $1" "$2" "$3 " "$4 " "$5 " " $6}'

I can read but how can I write name of the file from which I read and appending the new data from next file
Sponsored Links
    #3  
Old 01-28-2013
Peasant's Avatar
Peasant Peasant is online now
Registered User
 
Join Date: Mar 2011
Last Activity: 19 December 2014, 4:05 AM EST
Posts: 685
Thanks: 18
Thanked 153 Times in 149 Posts
Use internal awk variable FILENAME
    #4  
Old 01-28-2013
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
ok you mean
Code:
{print filename, $1......}

right..but without using cat how can I append to new file
Sponsored Links
    #5  
Old 01-28-2013
Peasant's Avatar
Peasant Peasant is online now
Registered User
 
Join Date: Mar 2011
Last Activity: 19 December 2014, 4:05 AM EST
Posts: 685
Thanks: 18
Thanked 153 Times in 149 Posts
You will redirect it to a new file awk '{ commands } ' file > newfile
Sponsored Links
    #6  
Old 01-28-2013
nex_asp nex_asp is offline
Banned
 
Join Date: Dec 2012
Last Activity: 21 May 2013, 2:14 AM EDT
Location: India
Posts: 70
Thanks: 20
Thanked 0 Times in 0 Posts
If we do so only last files data will be written to file...other files data will be overwritten....
am doing by
Code:
cat *.txt > new.xyz

by generating n number of text files from n number of input file
Sponsored Links
    #7  
Old 01-28-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 7 November 2014, 10:50 AM EST
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
Hope this is what you want..


Code:
awk 'FNR == 2 {print FILENAME,$1,$2,$3,$4,$5,$6}' *.txt >> new.xyz

The Following User Says Thank You to pamu For This Useful Post:
nex_asp (01-28-2013)
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
Read file from nth line to specific character laalesh Shell Programming and Scripting 3 03-22-2012 09:58 AM
read file line by line print column wise rocking77 Shell Programming and Scripting 2 12-07-2010 08:02 AM
How to read the value from a specific line and column BASH f_o_555 Shell Programming and Scripting 5 01-12-2010 08:57 AM
How to read the value from a specific line and column in to a csh variable Radamez Shell Programming and Scripting 2 01-09-2009 04:19 AM
Retrieve line from a file based on a value in specific column efernandes UNIX for Dummies Questions & Answers 1 01-27-2007 11:04 AM



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