Find and print in multiple columns | Unix Linux Forums | Linux

  Go Back    


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Find and print in multiple columns

Linux


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-08-2012
girlofgenuine girlofgenuine is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 8 October 2012, 9:10 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Find and print in multiple columns

Hi all,
My input file is :
Code:
0 13400000 sil
13400000 14400000 a
14400000 14900000 dh
14900000 15300000 a
15300000 16500000 R
16500000 17000000 k
17000000 17300000 u
17300000 17600000 th
17600000 17900000 sil
17900000 18400000 th
18400000 18900000 a
18900000 19600000 g
19600000 19900000 u
19900000 20500000 n
20500000 20800000 dh
20800000 21600000 a
21600000 22200000 b
22200000 22800000 a
22800000 23300000 d
23300000 24600000 i
24600000 28700000 sil
28700000 30600000 E
30600000 31100000 dh
31100000 32400000 A
32400000 32700000 v
32700000 33100000 a
33100000 33700000 dh
33700000 34100000 u
34100000 34400000 sil
34400000 35000000 k
35000000 35500000 o
35500000 36500000 qn
36500000 36900000 ch
36900000 37300000 a
37300000 38100000 m
38100000 38600000 sil

the thing is to find the extract the words in 3rd column and also to find the start duration and end duration of it.That is the output should be
Code:
13400000 17600000 adhaRkuth
17900000 24600000 thagundhabadi
28700000 34100000 EdhAvadhu
34400000 38100000  koqncham

I wrote a script.It picks up everthing.But it is not coming in an aligned manner.
my code is :
Code:
while ()
    set a = `cat $word | head -$file |tail -1 | cut -d " " -f3`
    set b = `cat $word | head -$file |tail -1 | cut -d " " -f2`
    set c = `cat $word | head -$file |tail -1 | cut -d " " -f1`
@ nextline = $file  + 1
    set i = `cat $word | head -$nextline | tail -1 | cut -d " " -f3`
    set j = `cat $word | head -$nextline | tail -1 | cut -d " " -f2`
    set k = `cat $word | head -$nextline | tail -1 | cut -d " " -f1`
@ prevline = $file  - 1
    set x = `cat $word | head -$prevline | tail -1 | cut -d " " -f3`
    set y = `cat $word | head -$prevline | tail -1 | cut -d " " -f2`
    set z = `cat $word | head -$prevline | tail -1 | cut -d " " -f1`
if ($a == sil && $b == $k) then
        echo $k $y
else if ($a == sil && $b != $k) then
        echo $y
else
        echo "$a\c"
endif

my output is :
Code:
13400000
adhaRkuth17900000 17600000
thagundhabadi28700000 24600000
EdhAvadhu34400000 34100000
koqncham38600000 38100000

Moderator's Comments:
Please use code tags

Last edited by jim mcnamara; 10-08-2012 at 09:52 AM..
Sponsored Links
    #2  
Old 10-08-2012
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 2 May 2014, 7:14 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 112 Times in 98 Posts
Try...
Code:
awk '$3=="sil"{if(p)print p,$1,w;w="";getline;p=$1}{w=w $3}' file

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
Awk match multiple columns in multiple lines in single file jacobs.smith Shell Programming and Scripting 2 06-27-2012 09:18 AM
Awk find in columns with "if then" statement and print results charles33 Shell Programming and Scripting 4 01-09-2012 04:41 AM
Need to find a column from one file and print certain columns in second file jpkumar10 Shell Programming and Scripting 1 12-07-2011 01:30 AM
awk command to print multiple columns coolguyamy Shell Programming and Scripting 2 12-23-2010 09:27 AM
I need to find one command from multiple files and need to print that file which contains neede com vijays3 Shell Programming and Scripting 2 10-20-2009 07:44 AM



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