Find and print in multiple columns


 
Thread Tools Search this Thread
Operating Systems Linux Find and print in multiple columns
# 1  
Old 10-08-2012
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:
Mod Comment Please use code tags

Last edited by jim mcnamara; 10-08-2012 at 10:52 AM..
# 2  
Old 10-08-2012
Try...
Code:
awk '$3=="sil"{if(p)print p,$1,w;w="";getline;p=$1}{w=w $3}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print multiple required columns dynamically in a file using the header name?

Hi All, i am trying to print required multiple columns dynamically from a fie. But i am able to print only one column at a time. i am new to shell script, please help me on this issue. i am using below script awk -v COLT=$1 ' NR==1 { for (i=1; i<=NF; i++) { ... (2 Replies)
Discussion started by: balu1234
2 Replies

2. UNIX for Beginners Questions & Answers

Print multiple columns in scientific notation

Hi everybody, I have file 1 with 15 columns, I want to change the formatting of the numbers of columns 10,11 and 12 in the scientific notation. I used the Following script: awk '{print $10}' file1.dat | awk '{printf "%.2e\n", $1}' > file2.dat awk '{print $11}' file1.dat | awk '{printf... (7 Replies)
Discussion started by: supernono06
7 Replies

3. UNIX for Beginners Questions & Answers

Count multiple columns and print original file

Hello, I have two tab files with headers File1: with 4 columns header1 header2 header3 header4 44 a bb 1 57 c ab 4 64 d d 5 File2: with 26 columns header1.. header5 header6 header7 ... header 22...header26 id1 44 a bb id2 57 ... (6 Replies)
Discussion started by: nans
6 Replies

4. Shell Programming and Scripting

Find columns in a file based on header and print to new file

Hello, I have to fish out some specific columns from a file based on the header value. I have the list of columns I need in a different file. I thought I could read in the list of headers I need, # file with header names of required columns in required order headers_file=$2 # read contents... (11 Replies)
Discussion started by: LMHmedchem
11 Replies

5. Shell Programming and Scripting

Awk: is it possible to print into multiple columns?

Hi guys, I have hundreds file like this, here I only show two of them: file 1 feco4_s_BB95.log ZE_1=-1717.5206260 feco4_t_BB95.log ZE_1=-1717.5169250 feco5_s_BB95.log ZE_1=-1830.9322060... (11 Replies)
Discussion started by: liuzhencc
11 Replies

6. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

7. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

8. Shell Programming and Scripting

Need to find a column from one file and print certain columns in second file

Hi, I need helping in finding some of the text in one file and some columns which have same column in file 1 EG cat file_1 aaaa bbbb cccc dddd eeee fffff gggg hhhh cat file_2 aaaa,abcd,effgh,ereref,name,age,sex,........... bbbb,efdfh,erere,afdafds,name,age,sex.............. (1 Reply)
Discussion started by: jpkumar10
1 Replies

9. Shell Programming and Scripting

awk command to print multiple columns

Hello Team, I have written following command which is giving output is as shown below. bash-3.00$ grep -i startup catalina.out | tail +2 | sed -n 1p | awk -F" " '{ for (x=1; x<=5; x++) { printf"%s\n", $x } }' Dec 19, 2010 3:28:39 PM bash-3.00$ I would like to modify above command to... (2 Replies)
Discussion started by: coolguyamy
2 Replies

10. Shell Programming and Scripting

I need to find one command from multiple files and need to print that file which contains neede com

Hi all i need your help .. I am having a multiple file in directory and i have find out the Rcopy word from these files and need to print those files which contains the Rcopy word Thanks and regards Vijay sahu (2 Replies)
Discussion started by: vijays3
2 Replies
Login or Register to Ask a Question