neversaint
neversaint

Reputation: 64004

How to get ONLY Second line with SED

How can I get second line in a file using SED

@SRR005108.1 :3:1:643:216
GATTTCTGGCCCGCCGCTCGATAATACAGTAATTCC
+
IIIIII/III*IIIIIIIIII+IIIII;IIAIII%>

With the data that looks like above I want only to get

 GATTTCTGGCCCGCCGCTCGATAATACAGTAATTCC

Upvotes: 41

Views: 82747

Answers (5)

Max Poon
Max Poon

Reputation: 119

cat your_file | head -2 | tail -1

Upvotes: 3

potong
potong

Reputation: 58391

This might work for you:

sed '2q;d' file

Upvotes: 7

Jonathan
Jonathan

Reputation: 12025

You don't really need Sed, but if the pourpose is to learn... you can use -n

n read the next input line and starts processing the newline with the command rather than the first command

sed -n 2p somefile.txt

Edit: You can also improve the performance using the tip that manatwork mentions in his comment:

sed -n '2{p;q}' somefile.txt

Upvotes: 54

Karoly Horvath
Karoly Horvath

Reputation: 96258

This will print the second line of every file:

awk 'FNR==2'

and this one only the second line of the first file:

awk 'NR==2'

Upvotes: 16

Jacob
Jacob

Reputation: 43219

You always want the second line of a file? No need for SED:

head -2 file | tail -1

Upvotes: 23

Related Questions