The UNIX and Linux Forums  

Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
google unix.com



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.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
visualizzazione cambiando variabile in un posto sullo schermo in ksh raidzero Shell scripting e di programmazione 7 09-25-2008 10:24 AM
rieseguire. dopo aver cambiato profilo variabile sboxtops AIX 2 09-02-2008 03:19 PM
l'esecuzione dello script bash con una variabile in una sola riga shoeb Shell scripting e di programmazione 1 07-06-2008 05:14 AM
IFS cambiando il valore della variabile pvar Shell scripting e di programmazione 1 02-25-2005 06:21 PM
Molto semplice domanda su come modificare PS1 variabile in fase di avvio! abidmalik UNIX for Dummies Domande & Risposte 2 08-26-2002 02:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #1 (permalink)  
Old 11-18-2008
sx3v1l_1n51de sx3v1l_1n51de is offline
Utente Registrato
  
 

Iscriviti Data: gennaio 2005
Interventi: 27
Talking Aiuto con script awk, cambiando la FS per una singola variabile

Ciao a tutti, nel mese di nuovo ad awk e apprezzi, se lei mi dicesse come fare questo, ho un file con più voci di questo tipo:

Codice:
2008-09-09 21:57:45   44  403 CUSTOM_EVENT                      Upgrade - end1
2008-09-09 21:57:46   45  403 CUSTOM_EVENT                      Component Check - start
2008-09-09 21:57:56   46  403 CUSTOM_EVENT                      Component Check - end
2008-09-09 21:57:56   47  403 CUSTOM_EVENT                      OSChecksum - start
2008-09-09 21:59:15   48  403 CUSTOM_EVENT                      OSChecksum - end
2008-09-09 21:59:15   49  403 CUSTOM_EVENT                      SELLogCheck - start
2008-09-09 22:01:39   50  403 CUSTOM_EVENT                      SELLogCheck - end
2008-09-09 22:01:40   51  403 CUSTOM_EVENT                      USB to Serial Connection Test - start
2008-09-09 22:43:46   52  403 CUSTOM_EVENT                      USB to Serial Connection Test - start
2008-09-09 22:44:15   53  403 CUSTOM_EVENT                      MemoryCheck - start
2008-09-09 22:44:16   54  403 CUSTOM_EVENT                      MemoryCheck - end
nel tentativo di ottenere i valori su l'ultimo campo, che potrebbe essere la descrizione della manifestazione (ad esempio, Connessione USB a seriale Test - start), ma ho bisogno di ulteriori separato questo campo con un "-" per sapere se il test ha iniziato o chiuso, l'ultimo campo è un po 'variabile in modo figurato i y potrebbe usare qualcosa di simile a questo:

cat $ 1 | awk '(description \u003d $ 6 "" $ 7 "" $ 8 "" $ 9 "" $ 10 "" $ 11 "" 12 $ "" $ 13 "" 14 $ "" $ 15; stampa descrizione)'

prima trovare tutti i campi da 6 a 15, e poi, cambiando i tryed FS - e stampare il secondo campo ...

cat $ 1 | awk '(description \u003d $ 6 "" $ 7 "" $ 8 "" $ 9 "" $ 10 "" $ 11 "" 12 $ "" $ 13 "" 14 $ "" $ 15; FS \u003d "-"; stampa descrizione $ 2)'

naturalmente, che stampa il secondo campo di tutta la linea, che è l'anno ... hehe ... c'è un modo per dire awk per la variabile di uscita del secondo campo delimitato da un "-"?

ringrazia tutti
  #2 (permalink)  
Old 11-18-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Iscriviti Data: gennaio 2007
Ubicazione: Варна, България / Milano, Italia
Messaggi: 2.892
Con AWK:

Codice:
awk '{
  for (i=6; i<=NF; i++) 
    s = s ? s FS $i : $i    
  split(s, t, "-")
  print "desc:", t[1], "state:", t[2]
  s = ""  
}' infile
Con Perl:

Codice:
perl -lane'
  print "desc: @F[5..$#F-2] state: $F[-1]"
  ' infile
  #3 (permalink)  
Old 11-18-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Iscriviti Data: gennaio 2007
Ubicazione: Варна, България / Milano, Italia
Messaggi: 2.892
In realtà, non è necessario dividere esplicitamente con AWK:

Codice:
awk '{
  for (i=6; i<=NF-2; i++) 
    s = s ? s FS $i : $i    
  print "desc:", s, "state:", $NF
  s = ""  
}' infile

Ultimo a cura di radoulov; al 11/18/2008 04:17 PM..
  #4 (permalink)  
Old 11-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Iscriviti Data: dicembre 2007
Location: Home di 17-volte campione del mondo Boston Celtics
Interventi: 1.311
Cool Non siete sicuri del vostro risultato desiderato, ma

Ho aggiunto un commento a dimostrare che i due settori sono stati separati, e ha aggiunto la "ed" il ricorso al verbo (solo perché suona meglio così).

Codice:
> cat file74
2008-09-09 21:57:45   44  403 CUSTOM_EVENT                      Upgrade - end1
2008-09-09 21:57:46   45  403 CUSTOM_EVENT                      Component Check - start
2008-09-09 21:57:56   46  403 CUSTOM_EVENT                      Component Check - end
2008-09-09 21:57:56   47  403 CUSTOM_EVENT                      OSChecksum - start
2008-09-09 21:59:15   48  403 CUSTOM_EVENT                      OSChecksum - end
2008-09-09 21:59:15   49  403 CUSTOM_EVENT                      SELLogCheck - start
2008-09-09 22:01:39   50  403 CUSTOM_EVENT                      SELLogCheck - end
2008-09-09 22:01:40   51  403 CUSTOM_EVENT                      USB to Serial Connection Test - start
2008-09-09 22:43:46   52  403 CUSTOM_EVENT                      USB to Serial Connection Test - start
2008-09-09 22:44:15   53  403 CUSTOM_EVENT                      MemoryCheck - start
2008-09-09 22:44:16   54  403 CUSTOM_EVENT                      MemoryCheck - end

> cut -c65- file74 | awk '{FS="-"}{print $1" _which was_ "$2"ed"}'
Upgrade _which was_ -ed
Component Check  _which was_  started
Component Check  _which was_  ended
OSChecksum  _which was_  started
OSChecksum  _which was_  ended
SELLogCheck  _which was_  started
SELLogCheck  _which was_  ended
USB to Serial Connection Test  _which was_  started
USB to Serial Connection Test  _which was_  started
MemoryCheck  _which was_  started
MemoryCheck  _which was_  ended
Closed Thread

Segnalibri

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 Su




Tutti gli orari sono GMT -4. La data di oggi è 11:17 PM.


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-2009. Tutti i diritti Reserved.Ad di gestione da RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0