Sponsored Content
Top Forums Shell Programming and Scripting Help with extract info if fulfill condition required Post 302643331 by perl_beginner on Saturday 19th of May 2012 10:01:54 PM
Old 05-19-2012
Help with extract info if fulfill condition required

Input file (4 DATA record shown in this case):
Code:
DATA       AA0110            
ACCESSION   AA0110
VERSION     AA0110  GI:157412239
FEATURES             Location/Qualifiers
     length            1..1170
                      1..1700
                     /length="1170"
     position            1..1170
                     /length="1170"
     band             1..948
                     /length="948"
//

DATA       BC599              
DEFINITION  USA
ACCESSION   BC599
VERSION     BC599  GI:239744030
FEATURES             Location/Qualifiers

     position          1..3159
                     /length="3159"
     length            1..40000
                     /length="40000"
//

DATA       HI101               
DEFINITION  UK
ACCESSION   HI101
VERSION     HI101  GI:239745142

FEATURES             Location/Qualifiers

     band             1..757
                     /length="757"
     length            1..747
                     /length="747"
//

DATA       AVE111
ACCESSION   AVE111
VERSION     AVE111  GI:157412223
FEATURES             Location/Qualifiers
     position            1..1170
                     /length="1170"
//

Desired output file:
Code:
157412239 1170
239744030 40000
239745142 747
157412223 -

Condition required:
1. The first column info of desired output file is extracted from the line shown "VERSION" and extract the content after GI:;
2. The second column info of desired output file is extracted from the line that shown "/length="XXX"" after "length" word;
3. If first column info of desired output file is available but lack of column 2 info. Just put a "-" and print in desired output file;

Command try:
Code:
awk 'BEGIN {RS=""; FS="//"} /VERSION/ {for (i=1;i<=NF;i++) {if ($i~/\/length=/) {print $i}}}' input_file.txt
DATA       AA0110            
ACCESSION   AA0110
VERSION     AA0110  GI:157412239
FEATURES             Location/Qualifiers
     length            1..1170
                     /length="1170"
     position            1..1170
                     /length="1170"
     band             1..948
                     /length="948"

The command I try fail to give my desired output result Smilie
I was thinking to use "//" as field separator of each record.

Thanks for any advice.

---------- Post updated at 09:01 PM ---------- Previous update was at 04:54 AM ----------

Is there any advice or hints provided to solve my doubt?
I'm still stuck at solving this problem Smilie
Thanks in advance!

Last edited by perl_beginner; 05-22-2012 at 01:39 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

using cut to extract info

a simple question, how can i use cut (after using grep) to extract the last four digits on a line. so say i had a string http://blabla:9020, how would I extract the port?? -Fez (4 Replies)
Discussion started by: hafhaq
4 Replies

2. Shell Programming and Scripting

End of loop condition required???

Hi i have a variable with lots of tokens seperated with spaces. e.g VAR="ABC DEF GHSD GHQS TUTSD JHDTQ QDHQ CDQKDGQ WQUTQD DQUTQD DQJGDQ QDTQD WDQUTQDU QDUGQD QDJGQD DQUTDUQ QDUIDTQ" i want to separate all of the above tokens and call a script with each of the token e.g sh script.sh <TOKEN>... (4 Replies)
Discussion started by: skyineyes
4 Replies

3. AIX

Extract info

Anyone have a better idea to automate extraction of info like ... "uname" "ifconfig" "ps efl" "netstat -ao" etc. from several hundred aix, solaris, red hat boxes? without logging into each box and manually performing these tasks and dumping them to individual files? thanks for any input (1 Reply)
Discussion started by: chm0dvii
1 Replies

4. UNIX for Advanced & Expert Users

Required info on Pstack on solaris10

Hi All , I am wanted to know the #of thread ( Kernal & User ) created by the Process i was looking into the prstat PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP 994 httpd 126M 99M sleep 58 0 1:11.25 2.4% ns-httpd/33 997 httpd 114M 86M sleep 58 0 0:40.02 2.7% ns-httpd/22 995... (0 Replies)
Discussion started by: rajendra44
0 Replies

5. Shell Programming and Scripting

how to retrieve required specific info from the file

Hi I have a file which consists of a number in the square brackets, followed by the blank line, then several lines which describe this number. This pattern is repeated several thousands time. The number in the brackets and the decription of it is unique. For example: ASRVSERV=1241GD;... (2 Replies)
Discussion started by: aoussenko
2 Replies

6. Shell Programming and Scripting

Extract info from csv

I have some input file, which contains some lines which are comma separated. Eg. a,b,id=999],d d,f,g,id=345],x x,y,x,s,id=677],y I run a loop to read the lines one by one. What i want is to extract the value on the right of id=. I cannot do it by Awk, since the column number is not fixed.... (5 Replies)
Discussion started by: indianjassi
5 Replies

7. Solaris

Info required zones in solaris

Can anyone explain me what is the use of zones in solaris. Also how to find whether it is a local or global zone. (1 Reply)
Discussion started by: rogerben
1 Replies

8. Solaris

prstat info required

Hi, I issued the following command on my solaris 10 and got the following info. prstat -Z PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP 1344 oracle 4872M 2392M sleep 59 0 145:49:50 0.1% oracle/1 17523 oracle 3976K 3672K cpu18 59 0 0:00:04 0.1% prstat/1 1550 oracle 3276M... (1 Reply)
Discussion started by: malikshahid85
1 Replies

9. Shell Programming and Scripting

If condition help required

I have a if condition it checks its pid exist it means it is running, otherwise not running. I am checking with ps x=`ps -fu myuserid|grep java| |grep -v grep | awk '{print $2}'` if then ............ Above code is giving integer error, because currently process of java is... (4 Replies)
Discussion started by: learnbash
4 Replies

10. Shell Programming and Scripting

How to extract info from pings.?

Hi guys, new to this forum. I am currently trying to extract the times from pinging a domain and list the top 3 and then also do the opposite i.e. list the bottom 3. so if I had this as a ping result (the bold part is what I want): 64 bytes from 193.120.166.90: icmp_seq=10 ttl=128 time=34.8... (5 Replies)
Discussion started by: acoding
5 Replies
All times are GMT -4. The time now is 09:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy