Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
Google Site



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.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #15 (permalink)  
Old 02-03-2009
vgersh99's Avatar
Moderatore
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.181
dato fran.csv:

Codice:
"hello","byebye"
"other","data"
"hello2","byebye2"
"hello3","byebye3"
"other","data"

e services.txt:

Codice:
define service{
use generic-service
service_description TCP_80
host_name hello,hello2,hello3,nochangematch
        contact_groups
        check_command
}

nawk-v sep \u003d ','-f fran.awk fran.csv services.txt
produce:

Codice:
define service{
use generic-service
service_description TCP_80
host_name byebye,byebye2,byebye3,nochangematch
        contact_groups
        check_command
}

dato nagios.cfg

Codice:
define host{
use generic-host
host_name hello
alias hello.hello
address 127.0.0.1
contact_groups mymail
parents hello3
}

eseguendo:
nawk-v sep \u003d '.' -f fran.awk fran.csv nagios.cfg
produce:

Codice:
define host{
use generic-host
host_name byebye
alias byebye.byebye
address 127.0.0.1
contact_groups mymail
parents byebye3
}

Controllare tutti i file contro i miei campioni - che tutte le opere per me.
Sponsored Links
  #16 (permalink)  
Old 02-03-2009
Utente Registrato
 

Iscriviti Data: febbraio 2009
Interventi: 12
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

  #17 (permalink)  
Old 02-03-2009
vgersh99's Avatar
Moderatore
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.181
strano, il tuo codice awk è la stessa come la mia.
hmmm ... - Deve essere qualcosa nel file di dati.
couxld si 'gatto-vet nagios.cfg.txt' e 'cat-vet test.csv' e dopo i risultati qui all'interno del tag del codice, pls.
  #18 (permalink)  
Old 02-03-2009
Utente Registrato
 

Iscriviti Data: febbraio 2009
Interventi: 12
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$

  #19 (permalink)  
Old 02-03-2009
vgersh99's Avatar
Moderatore
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.181
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
  #20 (permalink)  
Old 02-03-2009
Utente Registrato
 

Iscriviti Data: febbraio 2009
Interventi: 12
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.
  #21 (permalink)  
Old 02-03-2009
vgersh99's Avatar
Moderatore
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.181
heh
provare questo test.csv:

Codice:
"other","data"
"hello","byebye"
"hello2","byebye2"
"hello3","byebye3"
"other","data"

Sponsored Links
Closed Thread

Segnalibri

Tag
host_name, nagios, aggiornamento

Thread Tools Cerca in questo Thread
Cerca in questo Thread:

Ricerca Avanzata
Modalità di visualizzazione Vota questo thread
Vota questo thread:

Distacco regolamento
Tu non può post nuovo thread
Tu non può inviare una risposta
Tu non può postare allegati
Tu non può modificare i tuoi post

BB codice è Su
Smilies sono Su
[IMG] codice Su
Codice HTML è Chiuso
Trackbacks sono Su
Pingbacks sono Su
Refbacks sono Chiuso


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



Tutti gli orari sono GMT -4. La data di oggi è 06:00 AM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Traduzioni Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX e Linux Forum Content Copyright © 1993-2010. Tutti i diritti Reserved.Ad Management by RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0