user3551960
user3551960

Reputation: 3

changing the arrangement of a file

I have a file as shown below

>1BA9
394
395
396
397    
>1CA3
438
439
440
441
442  

I would like to arrange the above file like this

1BA9  394  397
1CA3  438  442

How is it possible with awk or sed?

Upvotes: 0

Views: 37

Answers (2)

potong
potong

Reputation: 58430

This might work for you (GNU sed):

sed '/^>/!{H;$!d};x;s/\n\([^\n]*\)\n.*\n/ \1 /p;x;h;d' file

This stores the multiline sequence from any line beginning with > to the next such sequence or end-of-file in the hold space. Then removes the unwanted parts and prints out the result.

Upvotes: 0

jaypal singh
jaypal singh

Reputation: 77105

awk -v RS='>' 'NR>1{print $1, $2, $NF}' file
  • Change the default Record Separator.
  • Print first, second and last fields.
  • Since your line starts with the separator use NR>1 to skip first empty record.

Upvotes: 1

Related Questions