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)&)&&
text-processing
add a comment |
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)&)&&
text-processing
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
add a comment |
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)&)&&
text-processing
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
text-processing
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
add a comment |
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
add a comment |
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>%%'
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
add a comment |
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>%%'
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
add a comment |
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>%%'
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
add a comment |
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>%%'
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>%%'
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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