Replace lines of two files by the corresponding line numbers.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace lines of two files by the corresponding line numbers.
# 1  
Old 10-07-2013
Replace lines of two files by the corresponding line numbers.

I want to replace lines. The files 1 are (separated by \t)
Code:
Gm01    phytozome9_0    three_prime_UTR 70641   70759   .       -       .       ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927
Gm01    phytozome9_0    three_prime_UTR 90230   90692   .       -       .       ID=PAC:26324253.three_prime_UTR.1;Parent=PAC:26324253;pacid=26324253

Files 2 are
Code:
>?_Gm01_70641_70759_-
GTTAGATGAGCTGGAAAGTGTTTCCATTCTGTCAATGACCCTTGCATGGG
ATGAATTTTCCTTCTCTACTTTTCAAGAAGCCCATTATTCGCTTCAAGTT
TCTCTAGACCAGGTGCCTG
>?_Gm01_70206_70267_-
TGTTCATGCTGCCTCTGTAATGGAGCAGGTTAAAGAGTTCCATTAGAAGA
GATGGTTTTGAG


I want output
Code:
>?_Gm01_pacid=26323927
GTTAGATGAGCTGGAAAGTGTTTCCATTCTGTCAATGACCCTTGCATGGG
ATGAATTTTCCTTCTCTACTTTTCAAGAAGCCCATTATTCGCTTCAAGTT
TCTCTAGACCAGGTGCCTG
>?_Gm01_pacid=26324253
TGTTCATGCTGCCTCTGTAATGGAGCAGGTTAAAGAGTTCCATTAGAAGA
GATGGTTTTGAG


Because the file 2 are generated from 1, so the sequence are the same. The first sequence in file 2 is from the first line in file 1, correspondingly.

Thank you.
Moderator's Comments:
Mod Comment Moderators have added CODE tags to several of your previous posts; and you have shown that you know how to do so. Please use CODE tags for all sample input, output, and code samples.

Last edited by Don Cragun; 10-07-2013 at 09:44 PM.. Reason: Add code tags.
# 2  
Old 10-07-2013
If your samples are representative of your actual input files, the following seems to do what you requested:
Code:
awk -F ';' '
FNR == NR {
        p[FNR] = $NF
        next
}       
/^>/ {  printf(">?_Gm01_%s\n", p[++oc])
        next
}       
1' "Files 1" "Files 2"

I strongly suggest that you tell whoever is producing your input files that there will be fewer mistakes made if data file with names that DO NOT contain space characters are used.

If you want to try this on a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk rather than /bin/awk or /usr/bin/awk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

2. Shell Programming and Scripting

Delete several lines if the first line contain numbers > 200

I have a file of the following format: $data1 size 1278 dataw datat datau datai $data2 size 456 datak dataf datat datay datal $data3 size 154 datag datas datat datar datas (8 Replies)
Discussion started by: FelipeAd
8 Replies

3. Shell Programming and Scripting

Replace a multi-line strings or numbers

Hi I have no experience in Unix so any help would be appreciated I have the flowing text 235543 123 45654 199 225 578 45654 199 225 I need to find this sequence from A file 45654 199 225 (22 Replies)
Discussion started by: khaled79
22 Replies

4. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

5. Shell Programming and Scripting

sed&awk: replace lines with counting numbers

Dear board, (I am trying to post this the 3rd time, seems there's some conflicts with my firefox with this forum, now use IE) ------ yes, I have searched the forum, but seems my ? is too complicated. ------------origianl file --------------- \storage\qweq\ertert\ertert\3452\&234\test.rec... (4 Replies)
Discussion started by: oUo
4 Replies

6. Shell Programming and Scripting

Replace 2nd column of CSV file with numbers on line

I have a csv file with occasional multiple entries in the second column. 111111,104,07-24-2011,3.15,N, 222222,020 140,07-24-2011,10.00,N,I want the result 111111,104,07-24-2011,3.15,N, 222222,020,07-24-2011,10.00,N, 222222,140,07-24-2011,10.00,N, I know I can get the output of the second... (5 Replies)
Discussion started by: ffdstanley
5 Replies

7. Shell Programming and Scripting

script to replace numbers on lines according to condition on the same line

hello everyone my file contains many records, the following is a sample: BEGIN ASX1500000050002010120000000308450201012000177 ASX1100002000000201012000000038450201012000220 ASX1600100005000201012000000038450020101200177 ASX1900100006000201067000000058450020101200177... (2 Replies)
Discussion started by: neemoze
2 Replies

8. Shell Programming and Scripting

Delete lines with line numbers.

Hi, I have a file will 1000 lines.... I want to deleted some line in the file... like 800-850 lines i want to remove in that... can somebody help me..? thanks. (2 Replies)
Discussion started by: Kattoor
2 Replies

9. Shell Programming and Scripting

Help required in displaying lines exceeding 79 chars along with their line numbers ??

Hi folks, I am looking for a solution to display those lines in any file that contains 80 or more characters along with their corresponding line number in the file. The below script will print the lines with their corresponding line numbers... sed = Sample.cpp | sed 'N;s/\n/\t/;... (8 Replies)
Discussion started by: frozensmilz
8 Replies

10. Shell Programming and Scripting

display lines b/w given line numbers

write a shell script that accepts a file name starting and ending line numbers as arguments and displays all the lines between the given line numbers:b:.help is appreciated.thank you. (3 Replies)
Discussion started by: shawz
3 Replies
Login or Register to Ask a Question