|
|
|
|
Google Site
|
|||||||
| Forum | Registrati | Blog | Man Pages | Regole Forum | Collegamenti | Album | FAQ | Utenti | Calendario | Ricerca | Today's Posts | Mark Forums Read |
| Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui. |
![]() |
|
|
Thread Tools | Cerca in questo Thread | Rate Thread | Modalità di visualizzazione |
| Sponsored Links |
|
|
|
|||
|
Molto strano. Controllati, la prova:
cat fran4.awk Codice:
BEGIN {
FScsv=","
FScfg=FS
if (sep=="") sep="."
qq=sprintf("%c", 034)
}
FNR==NR && FNR==1 {FS=FScsv;$1=$1}
FNR!=NR && FNR==1 {FS=FScfg; $1=$1}
FNR==NR {gsub(qq, "", $1);gsub(qq, "", $2); csv[$1]=$2; next}
!/{/ {
n=split($2, _a,sep)
for(i=1; i<=n; i++)
if (_a[i] in csv) _a[i]=csv[_a[i]]
for(i=1; i<=n; i++)
$2=(i==1) ? _a[i] : $2 sep _a[i]
}
1
cat test.csv Codice:
"hello","byebye" "other","data" "hello2","byebye2" "hello3","byebye3" "other","data" cat services.txt Codice:
define service{
use generic-service
service_description TCP_80
host_name hello,hello2,hello3,nochangematch
contact_groups
check_command
}
Esecuzione di codice: nawk-v sep \u003d ','-f fran4.awk test.csv services.txt Codice:
define service{
use generic-service
service_description TCP_80
host_name hello,byebye2,byebye3,nochangematch
contact_groups
check_command
}
Non è cambiata prima ciao cat nagios.cfg.txt Codice:
define host{
use generic-host
host_name hello
alias hello.hello
address 127.0.0.1
contact_groups mymail
parents hello3
}
Esecuzione di codice: nawk-v sep \u003d '.' -f fran4.awk test.csv nagios.cfg.txt Codice:
define host{
use generic-host
host_name hello
alias hello.hello
address 127.0.0.1
contact_groups mymail
parents byebye3
}
Cambiato solo genitori campo. È fran4.awk ultimo codice, gli incontri il vostro? Solo nel caso in cui ha fatto per tutti i file e dos2unix e: -i file fran4.awk test.csv nagios.cfg.txt services.txt Codice:
fran4.awk: text/plain charset=us-ascii test.csv: text/plain charset=us-ascii nagios.cfg.txt: text/plain charset=us-ascii services.txt: text/plain charset=us-ascii |
|
|||
|
cat-vet nagios.cfg.txt
Codice:
define host{$
use generic-host$
host_name hello$
alias hello.hello$
address 127.0.0.1$
contact_groups mymail$
parents hello3$
}$
cat-vet test.csv Codice:
"hello","byebye"$ "other","data"$ "hello2","byebye2"$ "hello3","byebye3"$ "other","data"$ cat-vet services.txt Codice:
define service{$
use generic-service$
service_description TCP_80$
host_name hello,hello2,hello3,nochangematch$
contact_groups $
check_command $
}$
cat-vet fran4.awk Codice:
BEGIN {$
FScsv=","$
FScfg=FS$
$
if (sep=="") sep="."$
$
qq=sprintf("%c", 034)$
}$
FNR==NR && FNR==1 {FS=FScsv;$1=$1}$
FNR!=NR && FNR==1 {FS=FScfg; $1=$1}$
FNR==NR {gsub(qq, "", $1);gsub(qq, "", $2); csv[$1]=$2; next}$
$
!/{/ {$
n=split($2, _a,sep)$
for(i=1; i<=n; i++)$
if (_a[i] in csv) _a[i]=csv[_a[i]]$
for(i=1; i<=n; i++)$
$2=(i==1) ? _a[i] : $2 sep _a[i]$
}$
1$
|
|
||||
|
hmm ...... questo è strano - funziona bene qui. Sembra che stai avendo problemi con la ricerca di "ciao" in test.csv file.
nagios.cfg.txt potrebbe cambiare in questo modo: Codice:
define host{
use generic-host
host_name other
alias other.other
address 127.0.0.1
contact_groups mymail
parents hello3
}
e: nawk-v sep \u003d '.' -f fran4.awk test.csv nagios.cfg.txt |
|
|||
|
Sì, se il passaggio ad "altri", quindi le opere
cat nagios.cfg.txt Codice:
define host{
use generic-host
host_name other
alias other.other
address 127.0.0.1
contact_groups mymail
parents hello3
}
nawk-v sep \u003d '.' -f fran4.awk test.csv nagios.cfg.txt Codice:
define host{
use generic-host
host_name data
alias data.data
address 127.0.0.1
contact_groups mymail
parents byebye3
}
Lavora, come un campo Poi di nuovo con questo concetto: cat nagios.cfg.txt Codice:
define host{
use generic-host
host_name hello
alias other.hello2
address 127.0.0.1
contact_groups mymail
parents hello3
}
nawk-v sep \u003d '.' -f fran4.awk test.csv nagios.cfg.txt Codice:
define host{
use generic-host
host_name hello
alias data.byebye2
address 127.0.0.1
contact_groups mymail
parents byebye3
}
Vedete, ciao host_name in campo non è cambiata. tutti gli altri campi okey. Questo è come il mio awk odia "ciao". Si vuole che sia il "inferno ' ![]() Appena scherzando .. ma sul serio .. Molto strano caso. |
![]() |
| Segnalibri |
| Tag |
| host_name, nagios, aggiornamento |
| Thread Tools | Cerca in questo Thread |
| Modalità di visualizzazione | Vota questo thread |
|
|
Più di UNIX e Linux Forum Argomenti potreste trovare utili
|
||||
| Filo | Thread Starter | Forum | Risposte | Ultimo Post |
| confrontare XML / flat file con la struttura del file system UNIX | shafi2all | Programmazione | 6 | 08-15-2008 03:15 AM |
| Awk per convertire un file flat di file CSV | rkumudha | Shell scripting e di programmazione | 14 | 07-17-2008 10:48 PM |
| match stringa in un file in un file in una directory | Jae | Shell scripting e di programmazione | 5 | 01-19-2008 01:11 AM |
| 5. Rimuovere il carattere da Field1 & Stampa | Raynon | Shell scripting e di programmazione | 9 | 12-14-2007 05:57 AM |
| Pivot Convertire file flat file | vskr72 | Shell scripting e di programmazione | 2 | 10-18-2005 05:41 PM |