Extracting text based on partial ID











up vote
1
down vote

favorite












I have a fastq file. Each entry in the file has four lines as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%*3-06,*($(&""#&$)(%.,,2/,#("#$##$')#$-13/*)(-/+(.-*'.+*0)&)&&


Lines do not have any empty line.



This is only one entry such that I have thousands of entries in the text file.



I have another file as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198
@e5cbeff3-5c28-46e4-a991-3dfded8505de


How do I extract all the four lines of each record using the list of these unique IDs?



Output should be following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%3-06,($(&""#&$)(%.,,2/,#("#$##$')#$-13/)(-/+(.-'.+*0)&)&&









share|improve this question
























  • Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
    – Mark Stewart
    Nov 27 at 13:47






  • 1




    yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
    – Trupti
    Nov 27 at 14:14






  • 2




    Please don't split up your example text. Show them exactly as is.
    – muru
    Nov 27 at 14:29










  • I have changed the example text. both the file entry starts with @
    – Trupti
    Nov 27 at 14:36










  • I'm guilty of splitting up the example text. Sorry!
    – Mark Stewart
    Nov 27 at 15:26















up vote
1
down vote

favorite












I have a fastq file. Each entry in the file has four lines as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%*3-06,*($(&""#&$)(%.,,2/,#("#$##$')#$-13/*)(-/+(.-*'.+*0)&)&&


Lines do not have any empty line.



This is only one entry such that I have thousands of entries in the text file.



I have another file as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198
@e5cbeff3-5c28-46e4-a991-3dfded8505de


How do I extract all the four lines of each record using the list of these unique IDs?



Output should be following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%3-06,($(&""#&$)(%.,,2/,#("#$##$')#$-13/)(-/+(.-'.+*0)&)&&









share|improve this question
























  • Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
    – Mark Stewart
    Nov 27 at 13:47






  • 1




    yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
    – Trupti
    Nov 27 at 14:14






  • 2




    Please don't split up your example text. Show them exactly as is.
    – muru
    Nov 27 at 14:29










  • I have changed the example text. both the file entry starts with @
    – Trupti
    Nov 27 at 14:36










  • I'm guilty of splitting up the example text. Sorry!
    – Mark Stewart
    Nov 27 at 15:26













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a fastq file. Each entry in the file has four lines as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%*3-06,*($(&""#&$)(%.,,2/,#("#$##$')#$-13/*)(-/+(.-*'.+*0)&)&&


Lines do not have any empty line.



This is only one entry such that I have thousands of entries in the text file.



I have another file as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198
@e5cbeff3-5c28-46e4-a991-3dfded8505de


How do I extract all the four lines of each record using the list of these unique IDs?



Output should be following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%3-06,($(&""#&$)(%.,,2/,#("#$##$')#$-13/)(-/+(.-'.+*0)&)&&









share|improve this question















I have a fastq file. Each entry in the file has four lines as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%*3-06,*($(&""#&$)(%.,,2/,#("#$##$')#$-13/*)(-/+(.-*'.+*0)&)&&


Lines do not have any empty line.



This is only one entry such that I have thousands of entries in the text file.



I have another file as following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198
@e5cbeff3-5c28-46e4-a991-3dfded8505de


How do I extract all the four lines of each record using the list of these unique IDs?



Output should be following



@0e249669-03e7-47e0-9bc2-a9bcaa35e198 runid=435beb2485d20d8e06f3b38ed907a08f8147fa77 read=100 ch=83 start_time=2018-10-27T12:20:46Z
ACGTATGCCCCGTTCAGTTGCACGTATTGCTATTAGTCACCATTACTTCTTCCTATTTGATGTGAAACCAAGGCAGAGATACTTTTCTGGGTGGTATTTGGGAGGTGGTGAGGCGATTCAAATCCAGGTCTCTCTGGGGACCTTGTTCTTAACCCCTGTACCCCCAGCCATCTGATATAATACTTTT
+
%)"+"""&(,,(,42(--/#)&()1,//./2,7,++8735/-+*#%3-06,($(&""#&$)(%.,,2/,#("#$##$')#$-13/)(-/+(.-'.+*0)&)&&






text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 at 15:50









muru

134k19285484




134k19285484










asked Nov 27 at 13:19









Trupti

5619




5619












  • Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
    – Mark Stewart
    Nov 27 at 13:47






  • 1




    yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
    – Trupti
    Nov 27 at 14:14






  • 2




    Please don't split up your example text. Show them exactly as is.
    – muru
    Nov 27 at 14:29










  • I have changed the example text. both the file entry starts with @
    – Trupti
    Nov 27 at 14:36










  • I'm guilty of splitting up the example text. Sorry!
    – Mark Stewart
    Nov 27 at 15:26


















  • Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
    – Mark Stewart
    Nov 27 at 13:47






  • 1




    yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
    – Trupti
    Nov 27 at 14:14






  • 2




    Please don't split up your example text. Show them exactly as is.
    – muru
    Nov 27 at 14:29










  • I have changed the example text. both the file entry starts with @
    – Trupti
    Nov 27 at 14:36










  • I'm guilty of splitting up the example text. Sorry!
    – Mark Stewart
    Nov 27 at 15:26
















Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
– Mark Stewart
Nov 27 at 13:47




Are the first four lines you show always in a block of four related records? So the "other list" is in a separate file, and you want to grab 4 records for each line in your other list, and ignore any other groups of four?
– Mark Stewart
Nov 27 at 13:47




1




1




yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
– Trupti
Nov 27 at 14:14




yes. based on the partial ID from another list (that is another file), I want to grab all the four lines
– Trupti
Nov 27 at 14:14




2




2




Please don't split up your example text. Show them exactly as is.
– muru
Nov 27 at 14:29




Please don't split up your example text. Show them exactly as is.
– muru
Nov 27 at 14:29












I have changed the example text. both the file entry starts with @
– Trupti
Nov 27 at 14:36




I have changed the example text. both the file entry starts with @
– Trupti
Nov 27 at 14:36












I'm guilty of splitting up the example text. Sorry!
– Mark Stewart
Nov 27 at 15:26




I'm guilty of splitting up the example text. Sorry!
– Mark Stewart
Nov 27 at 15:26










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I think the following command line will do the job. The data are in the file fast-file and the data-group names are in the file 'list'.



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list


or if you want to remove </br> tokens,



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list | sed 's%</br>%%'





share|improve this answer























  • Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
    – Trupti
    Nov 27 at 14:23








  • 1




    @Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
    – sudodus
    Nov 27 at 15:28










  • @Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
    – sudodus
    Nov 27 at 15:37












  • you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
    – Trupti
    Nov 28 at 6:00











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096488%2fextracting-text-based-on-partial-id%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










I think the following command line will do the job. The data are in the file fast-file and the data-group names are in the file 'list'.



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list


or if you want to remove </br> tokens,



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list | sed 's%</br>%%'





share|improve this answer























  • Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
    – Trupti
    Nov 27 at 14:23








  • 1




    @Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
    – sudodus
    Nov 27 at 15:28










  • @Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
    – sudodus
    Nov 27 at 15:37












  • you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
    – Trupti
    Nov 28 at 6:00















up vote
1
down vote



accepted










I think the following command line will do the job. The data are in the file fast-file and the data-group names are in the file 'list'.



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list


or if you want to remove </br> tokens,



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list | sed 's%</br>%%'





share|improve this answer























  • Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
    – Trupti
    Nov 27 at 14:23








  • 1




    @Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
    – sudodus
    Nov 27 at 15:28










  • @Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
    – sudodus
    Nov 27 at 15:37












  • you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
    – Trupti
    Nov 28 at 6:00













up vote
1
down vote



accepted







up vote
1
down vote



accepted






I think the following command line will do the job. The data are in the file fast-file and the data-group names are in the file 'list'.



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list


or if you want to remove </br> tokens,



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list | sed 's%</br>%%'





share|improve this answer














I think the following command line will do the job. The data are in the file fast-file and the data-group names are in the file 'list'.



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list


or if you want to remove </br> tokens,



while read line;do name=${line%% *}; grep -A3 "$name" fast-file ;done < list | sed 's%</br>%%'






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 27 at 15:36

























answered Nov 27 at 13:57









sudodus

21.7k32871




21.7k32871












  • Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
    – Trupti
    Nov 27 at 14:23








  • 1




    @Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
    – sudodus
    Nov 27 at 15:28










  • @Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
    – sudodus
    Nov 27 at 15:37












  • you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
    – Trupti
    Nov 28 at 6:00


















  • Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
    – Trupti
    Nov 27 at 14:23








  • 1




    @Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
    – sudodus
    Nov 27 at 15:28










  • @Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
    – sudodus
    Nov 27 at 15:37












  • you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
    – Trupti
    Nov 28 at 6:00
















Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
– Trupti
Nov 27 at 14:23






Thank you for your answer, but somehow it does not work. I would like all the four lines based on the match
– Trupti
Nov 27 at 14:23






1




1




@Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
– sudodus
Nov 27 at 15:28




@Trupti, Maybe the files are not linux files, but in some other format, for example DOS files or maybe there is some special formatting, that is not possible to see from your question. It would help, if you can upload real files somewhere, for example at paste.ubuntu.com
– sudodus
Nov 27 at 15:28












@Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
– sudodus
Nov 27 at 15:37






@Trupti, I modified the pattern for grep slightly (now there is an @ in the beginning of each line in the 'name file'. Please try again with the modified command line (and please upload a real 'fast file')).
– sudodus
Nov 27 at 15:37














you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
– Trupti
Nov 28 at 6:00




you were right. the files were not linux. I used the mac file. when I run the same one liner on linux it works. Thank you very much.
– Trupti
Nov 28 at 6:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096488%2fextracting-text-based-on-partial-id%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

數位音樂下載

格利澤436b

When can things happen in Etherscan, such as the picture below?