If your file have multiple blocks of the above text, for example, if your file contains:
| asn-query:
| BGP: 8.8.8.0/24 | Country: US
| Origin AS: 15169 - GOOGLE - Google Inc., US
| Peer AS: 1103 1239 2381 3257 6453
| asn-query:
| BGP: 2.2.2.0/24 | Country: XX
| Origin AS: 11111 - XXXXX - YYYYY Inc., US
| Peer AS: 1212 1313 1414 1515 1616
you could use the paste
utility to join every 4 lines to one line, e.g.
paste - - - - < the_above_file.txt
will produce two lines:
| asn-query: | BGP: 8.8.8.0/24 | Country: US | Origin AS: 15169 - GOOGLE - Google Inc., US | Peer AS: 1103 1239 2381 3257 6453
| asn-query: | BGP: 2.2.2.0/24 | Country: XX | Origin AS: 11111 - XXXXX - YYYYY Inc., US | Peer AS: 1212 1313 1414 1515 1616
and could modify each line as you wish, for example:
paste - - - - < asn.txt | sed 's/\|[[:blank:]]*//;s/://;s/[[:blank:]]*\|[[:blank:]]*/,/g'
will produce:
asn-query,BGP: 8.8.8.0/24,Country: US,Origin AS: 15169 - GOOGLE - Google Inc., US,Peer AS: 1103 1239 2381 3257 6453
asn-query,BGP: 2.2.2.0/24,Country: XX,Origin AS: 11111 - XXXXX - YYYYY Inc., US,Peer AS: 1212 1313 1414 1515 1616
same using perl (and explained)
paste - - - - < asn | perl -plE 's/\|\s*//; s/://; s/\s*\|\s*/,/g'
^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^
^ ^ ^
replace the 1st |+spaces with nothing--+ | |
| |
replace the 1st : with nothing ------------------+ |
|
replace all spaces + | + spaces with , -------------------+