Edit the last few fields in a line, starting from a particular string

1 réponse [Dernière contribution]
amenex
Hors ligne
A rejoint: 01/04/2015

The attached file contains a snippet of a long file wherein many (but not all) lines contain the string,"Peer-AS" and have a series of
[autonomous system] numbers following that word to the end of the line.
Here's an example of one such line, followed by the intended outcome, which confines those autonomous system numbers to the last column.
62.210.142.24 62-210-142-24.rev.poneytelecom.eu 62.210.0.0/16 FR AS12876 - Online SAS, FR Peer-AS-1239 3356 33891 196844
62.210.142.24 62-210-142-24.rev.poneytelecom.eu 62.210.0.0/16 FR AS12876 - Online SAS, FR Peer-AS1239-AS3356-AS33891-AS196844
It would also be advantageous to interchange that new last column with the column containing only a single dash "-" (and also following the earlier AS number that is followed by that dash) so that the new final column(s) contain the ownership information for the server. This task is complicated by the variable number of fields in each line of the file.

Pièce jointeTaille
Peer-problem.txt6.51 Ko
Magic Banana

I am a member!

I am a translator!

Hors ligne
A rejoint: 07/24/2010

Removing the many tabulations you have at the end of the lines (for some reason) and using "Peer-AS-" as a field separator:
$ awk -F 'Peer-AS-' -v OFS='\t' '{ gsub(/\t*$/, "") } $2 { gsub(/\t/, "-AS", $2); $2 = "Peer-AS" $2 } { print }' Peer-problem.txt