![]() |
|
|
google unix.com
|
|||||||
| Forum | Registrati | Regole Forum | Collegamenti | Album | FAQ | Members List | 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. |
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 |
![]() |
|
|
LinkBack | Thread Tools | Cerca in questo Thread | Rate Thread | Modalità di visualizzazione |
|
|
|
||||
|
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 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 ![]() |
|
|||||
|
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.. |
|
|||||
|
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
|
![]() |
| Segnalibri |
| Thread Tools | Cerca in questo Thread |
| Modalità di visualizzazione | Vota questo thread |
|
|