Hello
I have a output file that contains the next info:
host_name LET-234-WDFD-2
address 10.11.0.62
host_name XWERWE-234-WEDF-EMEEH-GIDF-3
address 10.11.32.48
host_name DFG-745-WE-EMEEEH-GIDF-4
address 10.11.32.176
host_name DFDFG-ERWG-BL-ETH-01-FV
address 198.18.1.107
host_name DFDFG-ERWG-BL-ETH-02-FV
address 198.18.1.108
host_name DFDFG-WEFEW-WEFWEF-01-ASDS
address 10.11.0.108
host_name DFDFG-SDF-UKLY-01-FGG
address 198.18.253.138
host_name DFDFG-SDF-UKLY-02-FGG
address 198.18.253.139
host_name DFDFG-SDF-UKLY-01-GGHTFGH2
The objective is delete host_name & adress an put ; to separate host_name and address:
LET-234-WDFD-2;10.11.0.62
XWERWE-234-WEDF-EMEEH-GIDF-3;10.11.32.48
DFG-745-WE-EMEEEH-GIDF-4;10.11.32.176
DFDFG-ERWG-BL-ETH-01-FV;198.18.1.107
DFDFG-ERWG-BL-ETH-02-FV;198.18.1.108
DFDFG-WEFEW-WEFWEF-01-ASDS;10.11.0.108
DFDFG-SDF-UKLY-01-FGG;198.18.253.138
DFDFG-SDF-UKLY-02-FGG;198.18.253.139
I try with cut, but any result
Could you help me? Thanks
Assuming a space between the strings and the data,try:
cut -d' ' -f2- file|paste -sd';\n'
awk 'FNR%2 {print name, $2;next}{name=$2}' OFS=';' myFile
Hello Thanks for your reply. I try with the metodes and doesn't work :-(. The result is:
cut -d' ' -f2- file|paste -sd';\n' extractcritiques.txt
host_name cedf-ddt ; address 10.14.138.3
host_name dfb-crft ; address 10.14.184.2
host_name cesdneb-cerferu ; address 10.14.184.3
host_name cenfeeb-derfx; address 10.14.139.10
awk 'FNR%2 {print name, $2;next}{name=$2}' OFS=';' extractcritiques.txt | more
;cdceb-adn
10.14.176.6;ceneb-fg
10.14.176.7;ceneb-arerfg
10.14.200.4;ceneb-arrefer
10.14.200.5;ceneb-brfer
10.14.244.96;ceneb-sacrf
10.14.244.97;ceneb-cacrf
I think the problem is the space in to the origen file:
host_name cendfseb-ardfdf
address 10.14.176.6
host_name cesdfb-arsdf
address 10.14.176.7
host_name csgb-atg
address 10.14.200.4
host_name certhrteb-artg
Sorry in my first message don't appear the spaces (or tabulations) because I put in (Wrap quote). awk is very interesting. I'm read the documentation in this moment.
Slight mod to vgersh's awk:
awk 'FNR%2 {name=$2; next} {print name, $2}' OFS=';' infile
alternatively:
awk '{name=$2; getline; print name, $2}' OFS=';' infile
1 Like
Thankss!!!!
When I read your reponse I'm try with:
You win
RudiC
October 3, 2012, 6:16am
7
small corrections to the suggestions will make them work.
1) remove excess spaces using sed:
sed 's/ */ /g;s/^ //' extractcritiques.txt|cut -d' ' -f2- |paste -sd';\n'
2) invert the result of the %2:
awk 'FNR%2==0 {print name, $2;next}{name=$2}' OFS=';' extractcritiques.txt
1 Like