1
">16RI1_0 M01230:42:000000000-AWMRD:1:1101:15012:1778 1:N:0:0 
TATCCGGATTTACTGGGTGTAAAGGGAGCGTAGGCGGCCATGCAAGTCAGAAGTGAAAAC
">16RA2_1 M01230:42:000000000-AWMRD:1:1101:15923:1780 1:N:0:0 
TTGTCCGGATTTATTGGGCGTAAAGCGAGCGCAGGCGGTTTCTTAAGTCTGATGTGAAAGC
">0VC3_7 M01230:42:000000000-AWMRD:1:1101:15805:1805 1:N:0:0 TCATGAAGAACTCCGATCGCGAAGGCAAGTGTCCGGGGTGCAACTGACGCTGAGGCTCGAA
">11VI2_15 M01230:42:000000000-AWMRD:1:1101:17657:1817 1:N:0:0 
GCGGCTTACTGGACTGTAACTGACGTTGAGGCTCGAAAGCGTGGGGAGCAAACAGGGCTC

Hello, I have a file containing information like this. I want to print all the lines starting with ">" sign and the next line but there is a condition the line starting with ">" sign should contain the letter V. Please help me.

  • 2
    The fasta file in the question has improperly formatted header lines, and one sequence lien is not on its own line. Please reformat. – Kusalananda Jan 31 '17 at 7:46
  • 1
    Yes, please edit your question and clarify. Is this your actual file or do you have a real fasta format file? Can we assume that all sequence information will always be on a single line? Fasta allows multiple sequence lines per entry. – terdon Jan 31 '17 at 9:33
4

With GNU sed (standard on Linux system), you can get the header line (containing a V anywhere on it) and the first line of the sequence from a fasta file like this:

sed -n '/^>.*V/,+1p' sequence.fa

This is assuming that the fasta file is properly formatted.

The -n turns off the default output and /^>.*V/,+1p will print any header line with a V in it, together with the immediately following line.

7

I want to print all the lines starting with ">" sign and the next line but there is a condition the line starting with ">" sign should contain the letter V.

This grep seems to work:

grep -A 1 '^">.*V'

Example:

grep -A 1 '^">.*V' file 
">0VC3_7 M01230:42:000000000-AWMRD:1:1101:15805:1805 1:N:0:0 TCATGAAGAACTCCGATCGCGAAGGCAAGTGTCCGGGGTGCAACTGACGCTGAGGCTCGAA
">11VI2_15 M01230:42:000000000-AWMRD:1:1101:17657:1817 1:N:0:0 
GCGGCTTACTGGACTGTAACTGACGTTGAGGCTCGAAAGCGTGGGGAGCAAACAGGGCTC
1

You said:

I want to print all the lines starting with ">" sign and the next line but there is a condition the line starting with ">" sign should contain the letter V

That's a good job for awk:

$ awk '/^">.*V/{print $0;getline line; print line}' input.txt                                                            
">0VC3_7 M01230:42:000000000-AWMRD:1:1101:15805:1805 1:N:0:0 
TCATGAAGAACTCCGATCGCGAAGGCAAGTGTCCGGGGTGCAACTGACGCTGAGGCTCGAA
">11VI2_15 M01230:42:000000000-AWMRD:1:1101:17657:1817 1:N:0:0 
GCGGCTTACTGGACTGTAACTGACGTTGAGGCTCGAAAGCGTGGGGAGCAAACAGGGCTC
  • Thaks a lot. it worked – Masum Billah Mar 13 '17 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.