Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to grep several words in file1, and use each word to grep what follows after its match in file2. And then I want to add the thing that followed the match to the word I used into file03, so that file03 contains:

word1 [the thing that was found using word1 in a grep in file2]
word2 [the thing that was found using word1 in a grep in file2]

Part of files I have are:

File1:

JAN1319964: PGSC|PGSC0003DMP400068385_PGSC0003DMT400096710 PGSC|PGSC0003DMP400062633_PGSC0003DMT400090958 PGSC|PGSC0003DMP400066271_PGSC0003DMT400094596 PGSC|PGSC0003DMP400064671_PGSC0003DMT400092996 PGSC|PGSC0003DMP400068967_PGSC0003DMT400097292
JAN1327159: PGSC|PGSC0003DMP400016823_PGSC0003DMT400024599 PGSC|PGSC0003DMP400017933_PGSC0003DMT400026257 Dul|Dul_comp58749_c0_seq2-1
JAN1330513: Des|Des_g36886.t1 PGSC|PGSC0003DMP400049952_PGSC0003DMT400073802

File2:

>Dul|Dul_g997.t1
ESECRVQYFSDDEVSPVTEVTGRRGSICVVCRLVPKASVSESSFLK
>Dul|Dul_g998.t1
MDDKRLWEEEERRRIAVRQREERGKIYERQKALEEQEKLAAIESYQDAIRREREEEERLKEKKKKKKKTEIRDDYLDDFLPRRNDRRIPDRDRSVKRRQTFESGRHAKEHAPPTKRRRGGEVGLSNILEEIVDTLKNNVNVSYLFLKPVTRKEAPDYHKYVKRPMDLSTIKERARKLEYKNRGQFRHDVAQITINAHLYNDGRNPGIPPLADQLLEICDYLLEENESILAEAESAI
>Dul|Dul_g999.t1
MDDKRLWEEEERRRIAVRQREERGKIYERQKALEEQEKLAAIESYQDAIRREREEEERLKEKKKKKKKTEIRDDYLDDFLPRRNDRRIPDRDRSVKRRQTFESGRHAKEHAPPTKRRRGGEVGLSNILEEIVDTLKNNVNVSYLFLKPVTRKEAPDYHKYVKRPMDLSTIKERARKLEYKNRGQFRHDVAQITINAHLYNDGRNPGIPPLADQLLEICDYLLEENESILAEAESGIEQ
>Des|Des_g1.t1
FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK

The output I want is for this example:

JAN1319964: PGSC|PGSC0003DMP400068385_PGSC0003DMT400096710 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400062633_PGSC0003DMT400090958 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400066271_PGSC0003DMT400094596 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400064671_PGSC0003DMT400092996 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400068967_PGSC0003DMT400097292  [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
JAN1327159: PGSC|PGSC0003DMP400016823_PGSC0003DMT400024599 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400017933_PGSC0003DMT400026257 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
Dul|Dul_comp58749_c0_seq2-1
JAN1330513: Des|Des_g36886.t1  [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK
PGSC|PGSC0003DMP400049952_PGSC0003DMT400073802 [the line after the match to this name]: FRKQTVELSESDDTSISVETEDAEIENGNSPPAGLSNTTKVQLKPLYRSTIQLTPHPDGLSNTNEIK

As you can see, I simply have some information missing in file1, which is contained in file2, and needs to be added to file1. If anyone knows how to do this I would greatly appreciate it!

share|improve this question

closed as off-topic by Seth May 8 at 20:12

  • This question does not appear to be about Ubuntu within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
This might be better off on unix.stackexchange.com because is does not seem I to be specifically related to Ubuntu. –  David Edwards Jun 13 '13 at 12:45
    
Ok, I will move it there instead, thank you for the information. –  Stenemo Jun 13 '13 at 14:06
    
If you've moved it somewhere else, please delete this question. –  Sparhawk Nov 2 '13 at 10:53
    
This question appears to be off-topic because it was cross posted. Please don't cross post. –  Seth May 8 at 20:12

Browse other questions tagged or ask your own question.