![]() |
Olá e boas-vindas de Estados Unidos para o UNIX e Linux Forum! Obrigado por visitar e fazer parte da nossa comunidade global.
|
|
google unix.com
|
|||||||
| Fóruns | Registar | Fórum Regimento | Ligações | Álbuns | FAQ | Lista deputados | Calendário | Pesquisa | Today's Posts | Mark Forums Read |
| Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui. |
Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
|
||||
| Fio | Thread Starter | Fórum | Respostas | Última postagem |
| display mudar variável em um lugar na tela em ksh | raidzero | Programação Shell Script e | 7 | 09-25-2008 10:24 |
| reexecute. perfil após mudar variável | sboxtops | AIX | 2 | 09-02-2008 03:19 |
| bash script execução com uma variável em uma única linha | shoeb | Programação Shell Script e | 1 | 07-06-2008 05:14 |
| IFS alterando a variável valor | pvar | Programação Shell Script e | 1 | 02-25-2005 06:21 |
| Muito simples pergunta sobre a evolução variável PS1 no arranque! | abidmalik | UNIX para Dummies Perguntas & Respostas | 2 | 08-26-2002 02:05 |
![]() |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Oi tudo, im novo para awk e apreciate seria se você poderia me dizer como fazer isso, eu tenho um arquivo com várias entradas como esta:
Código:
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; imprimir descrição)' primeiro eu recebo todos os campos 6-15 e, em seguida, i tryed mudar para o FS - e imprimir o segundo campo ... cat $ 1 | awk '(description \u003d $ 6 "" $ 7 "" $ 8 "" $ 9 "" $ 10 "" $ 11 "" $ 12 "" $ 13 "" $ 14 "" $ 15; FS \u003d "-"; imprimir descrição $ 2)' naturalmente, que imprime o segundo campo de toda a linha, que é o ano ... hehe ... existe uma maneira de dizer ao awk para a variável de saída do segundo campo delimitado por um "-"? agradece todos os ![]() |
|
|||||
|
Na verdade, você não precisa divisão explicitamente com Awk:
Código:
awk '{
for (i=6; i<=NF-2; i++)
s = s ? s FS $i : $i
print "desc:", s, "state:", $NF
s = ""
}' infile
Última edição por radoulov; em 11/18/2008 04:17.. |
|
|||||
|
Eu adicionei um comentário para mostrar que os dois campos foram separados, e acrescentou o "ed" para a ação verbal (só porque soa melhor assim).
Código:
> 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
|
![]() |
| Marcadores |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|