If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Query in awk/bash

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jan 2013
Posts: 3
Question Query in awk/bash

Hi,
I have two files:

Quote:
11.txt showing two patterns:

ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N
ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C
TER
ENDMDL
ATOM 1 N SER A 1 35.683 81.326 139.778 1.00 0.00 N
ATOM 2 CA SER A 1 35.422 82.736 139.929 1.00 0.00 C
TER
ENDMDL

File: c.txt

Number of groups: 40 3.95
Group: 0 Branches: 1
0 001
Centre: 001 Nodes: 1
Group: 1 Branches: 1
0 002
Centre: 002 Nodes: 1
Group: 2 Branches: 6
0 009
1 004
2 008
3 007
4 005
5 006
Centre: 006 Nodes: 6
ENDMDL is coming many times in 11.txt. I wish to retreive that pattern corresponds to the value of Id. It means, if I give input of 004 (Id) from group 2, then it should output the fourth repeat from 11. txt ending with ENDMDL.

Quote:
Id004.txt

Group2: Id 004
ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N
ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C
TER
ENDMDL
So, corresponding to value of Id from c.txt, I want to retreive the repeat at the number from 11.txt.

Please guide, how, corresponding to value of Id from c.txt, I can retreive the repeat at the number from 11.txt.
Also, I wish to retreive these patterns in individual files based on their Id, group, centre. For example:
group0.txt contains all patterns with Id
group1.txt contains all patterns with Id
group2.txt contains all patterns with Id
One file containing patterns with corresponding to centre ID
Id001.txt
Id002.txt
Id009.txt
............
............

Thanks
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Feb 2006
Posts: 172
In your example, For Id-004, Read from file(c.txt) line(1 004) how did you match it to these lines from file(11.txt):
Code:
ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N 
ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C 
TER
ENDMDL

To get this file(Id004.txt):
Code:
Group2: Id 004
ATOM 1 N SER A 1 35.092 83.194 140.076 1.00 0.00 N 
ATOM 2 CA SER A 1 35.216 83.725 138.725 1.00 0.00 C 
TER
ENDMDL
Reply With Quote
  #3 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 972
You could probably simplify the process by first converting 11.txt to a file that contains one line per group.
Code:
i=0
while read line1
do
   read line2
   read ter
   read endmdl
   i=`eval $i + 1`
   echo $i $line1 $line2 $ter $endmdl
done
With all the data on one line, it is only a matter of selecting the line that corresponds to Id.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jan 2013
Posts: 3
Thanks a lot
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On