Reputation: 3
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
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
Reputation: 77105
awk -v RS='>' 'NR>1{print $1, $2, $NF}' file
NR>1
to skip first empty record. Upvotes: 1