|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cut determinate values amb subst for ;
Hello I have a output file that contains the next info: Code:
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-GGHTFGH2The objective is delete host_name & adress an put ; to separate host_name and address: Code:
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 Last edited by Scrutinizer; 10-03-2012 at 06:02 AM.. Reason: code tags instead of quote tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Assuming a space between the strings and the data,try: Code:
cut -d' ' -f2- file|paste -sd';\n' |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
awk 'FNR%2 {print name, $2;next}{name=$2}' OFS=';' myFile |
|
#4
|
|||
|
|||
|
Hello Thanks for your reply. I try with the metodes and doesn't work :-(. The result is: Code:
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.10Code:
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-cacrfI think the problem is the space in to the origen file: Code:
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-artgSorry 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. Last edited by Scrutinizer; 10-03-2012 at 06:01 AM.. Reason: code tags instead of quote tags |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Slight mod to vgersh's awk: Code:
awk 'FNR%2 {name=$2; next} {print name, $2}' OFS=';' infilealternatively: Code:
awk '{name=$2; getline; print name, $2}' OFS=';' infile |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
capilla (10-03-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thankss!!!!
When I read your reponse I'm try with: Quote:
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
small corrections to the suggestions will make them work. 1) remove excess spaces using sed: Code:
sed 's/ */ /g;s/^ //' extractcritiques.txt|cut -d' ' -f2- |paste -sd';\n' 2) invert the result of the %2: Code:
awk 'FNR%2==0 {print name, $2;next}{name=$2}' OFS=';' extractcritiques.txt |
| The Following User Says Thank You to RudiC For This Useful Post: | ||
capilla (10-03-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A simple variable subst is not working | IMPe | Shell Programming and Scripting | 1 | 06-01-2012 08:49 AM |
| Compare values in two files. For matching rows print corresponding values from File 1 in File2. | Santoshbn | Shell Programming and Scripting | 10 | 05-21-2012 11:23 AM |
| Delete character in determinate position with sed/awk | maria_florencia | Shell Programming and Scripting | 4 | 01-20-2011 10:01 AM |
| assign subst|grep|sed command result to a variable | snowbiker99 | Shell Programming and Scripting | 5 | 11-14-2007 06:08 PM |
| Command param subst to reg expression | videsh77 | Shell Programming and Scripting | 5 | 12-21-2004 01:46 PM |
|
|