Select records and fields

Hi All
I would like to modify a file like this:

>antax gioq21 tris notes
abcdefghij
klmnopqrs
>betax gion32 ter notes2
tuvzabcdef
ahgskslsoo

in this:

>tris
abcdefghij
klmnopqrs
>ter
tuvzabcdef
ahgskslsoo

So, I would like to remove the first two fields(and output field 3) in record starts with > and to keep field1 in other records.
Any help?

Giuliano

awk '/^>/{print ">"$3;getline;print;getline;print}'
1 Like

Thank you a lot!
But (and it is my fault) in the example above I just put 2 lines, but the lines could be more that one and different in length ( getline could be still usefull?)

>antax gioq21 tris notes
abcdefghij
klmnopqrs
dfgdfgdsg
sddf
>betax gion32 ter notes2
tuvzabcdef
ahgs

output:

>tris
abcdefghij
klmnopqrs
dfgdfgdsg
sddf
>ter
tuvzabcdef
ahgs

Giuliano

Hi.

awk '/^>/{print ">"$3;next} {print}' file

producing:

>tris
abcdefghij
klmnopqrs
dfgdfgdsg
sddf
>ter
tuvzabcdef
ahgs

Note the importance of posting representative data sets.

Best wishes ... cheers, drl

1 Like
$ awk '/>/{$0 = ">"$3}1' file