Edit the last few fields in a line, starting from a particular string
- Anmelden oder Registrieren um Kommentare zu schreiben
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.
Anhang | Größe |
---|---|
Peer-problem.txt | 6.51 KB |
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
- Anmelden oder Registrieren um Kommentare zu schreiben