user3741035
user3741035

Reputation: 2545

grep line that follow a symbol

How do I grep the line that followes the @ symbol?

I though this should work: grep -A @ file

@SRR797059.1 HWIEAS269_0001:5:1:1049:4995 length=38
CGAGCTCCGGCTCGGAGGACCATACTATCGTATGCNGN
+SRR797059.1 HWIEAS269_0001:5:1:1049:4995 length=38
bbbbbbbbbbbbbb^bb]_^aR_]_b_b[_BBBBBBBB
@SRR797059.2 HWIEAS269_0001:5:1:1057:20746 length=38
GGATCTGTAAACATCCTCGACTGGAAGCTTACTATCGT

output

  CGAGCTCCGGCTCGGAGGACCATACTATCGTATGCNGN
  GGATCTGTAAACATCCTCGACTGGAAGCTTACTATCGT

Upvotes: 1

Views: 32

Answers (1)

jaypal singh
jaypal singh

Reputation: 77155

-A option needs a number after it which would suggest the number of lines you need to print.

From the man page:

>  -A num, --after-context=num
>              Print num lines of trailing context after each match. 

So you should try:

$ grep -A 1 '@' file 
@SRR797059.1 HWIEAS269_0001:5:1:1049:4995 length=38
CGAGCTCCGGCTCGGAGGACCATACTATCGTATGCNGN
--
@SRR797059.2 HWIEAS269_0001:5:1:1057:20746 length=38
GGATCTGTAAACATCCTCGACTGGAAGCTTACTATCGT

Answer for updated question:

$ awk 'p;{p=(/@/?1:0)}' file
CGAGCTCCGGCTCGGAGGACCATACTATCGTATGCNGN
GGATCTGTAAACATCCTCGACTGGAAGCTTACTATCGT

Set the flag for the line that contains @. Print the next line and disable it.

Upvotes: 1

Related Questions