The UNIX and Linux Forums  


Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



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
Converso Epoch Hora de Data e Hora Standard & Vice Versa DrivesMeCrazy Programação Shell Script e 5 02-07-2009 01:40
Para converter um arquivo para múltiplos formato legível formato ASCII gaur.deepti UNIX para Dummies Perguntas & Respostas 5 03-25-2008 03:03
converter mmddaa formato de data para ccyyddd formato? Bhups Programação Shell Script e 2 09-28-2006 12:30
como converter época tempo para readible formato? cin2000 Programação Shell Script e 11 12-19-2005 07:14
formato data / hora apresentação apalex Programação Shell Script e 6 04-19-2002 02:34

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 Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-18-2008
rk4k rk4k is offline
Usuário
  
 

Join Date: Nov 2008
Localização: / planet-earth/indonesia/jakarta /
Lugares: 11
Talking Converso Epoch tempo normal para formatar data formato tempo no mesmo arquivo

Eu tenho um arquivo chamado "suspeitos" com o conjunto de linhas como estas:


Código:
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '87.204.76.129', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 15485, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '118.125.238.96', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 23786, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '90.4.40.186', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 27542, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '84.90.16.109', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 64115, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '78.106.166.60', 'client_port': 45309, 'client': '10.64.68.143', 'server_port': 57587, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '218.161.75.90', 'client_port': 45309, 'client': '10.64.68.143', 'server_port': 14323, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 6, 'service': 'BitTorrent encrypted transfer', 'server': '208.53.147.63', 'client_port': 3647, 'client': '10.64.68.68', 'server_port': 31866, 'time': 1226534386L, 'serverhostname': ''}
{'protocol': 6, 'service': 'BitTorrent transfer', 'server': '87.120.14.250', 'client_port': 41607, 'client': '10.64.68.78', 'server_port': 22566, 'time': 1226534379L, 'serverhostname': ''}
{'protocol': 6, 'service': 'HTTP', 'server': '72.14.221.190', 'client_port': 51980, 'client': '10.64.68.68', 'server_port': 80, 'time': 1226880065L, 'serverhostname': ''}
{'protocol': 6, 'service': 'Undetermined', 'server': '92.97.199.57', 'client_port': 55456, 'client': '10.64.68.68', 'server_port': 25252, 'time': 1226880097L, 'serverhostname': ''}
{'protocol': 6, 'service': 'HTTP', 'server': '74.125.19.118', 'client_port': 54043, 'client': '10.64.68.68', 'server_port': 80, 'time': 1226880099L, 'serverhostname': ''}

Eu quero converter o domínio que contém 1226506312L ao normal formato de data. Eu encontrei o script para convertê-lo com a data comando com:


Código:
date -d '1970-01-01 '$1' seconds'

Eu quero converter o arquivo para que algo parecido com:


Código:
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '84.90.16.109', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 64115, 'time': Wed Nov 12 16:11:52, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '78.106.166.60', 'client_port': 45309, 'client': '10.64.68.143', 'server_port': 57587, 'time': Wed Nov 12 16:11:52, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '218.161.75.90', 'client_port': 45309, 'client': '10.64.68.143', 'server_port': 14323, 'time': Wed Nov 12 16:11:52, 'serverhostname': ''}
{'protocol': 6, 'service': 'BitTorrent encrypted transfer', 'server': '208.53.147.63', 'client_port': 3647, 'client': '10.64.68.68', 'server_port': 31866, 'time': Wed Nov 12 23:59:46 WIT 2008, 'serverhostname': ''}
{'protocol': 6, 'service': 'BitTorrent transfer', 'server': '87.120.14.250', 'client_port': 41607, 'client': '10.64.68.78', 'server_port': 22566, 'time': Wed Nov 12 23:59:46 WIT 2008, 'serverhostname': ''}
{'protocol': 6, 'service': 'HTTP', 'server': '72.14.221.190', 'client_port': 51980, 'client': '10.64.68.68', 'server_port': 80, 'time': Wed Nov 12 23:59:46 WIT 2008, 'serverhostname': ''}
{'protocol': 6, 'service': 'Undetermined', 'server': '92.97.199.57', 'client_port': 55456, 'client': '10.64.68.68', 'server_port': 25252, 'time': Wed Nov 12 23:59:46 WIT 2008, 'serverhostname': ''}
{'protocol': 6, 'service': 'HTTP', 'server': '74.125.19.118', 'client_port': 54043, 'client': '10.64.68.68', 'server_port': 80, 'time': Wed Nov 12 23:59:46 WIT 2008, 'serverhostname': ''}

Eu sei um pouco sobre awk, e pode convertê-lo com:


Código:
awk '{ print $7 }' FS="," suspected | awk '{ print $2 }' | cut -f1 -d"L" | while read line ; do sh datepoch $line ; done

mas o script apenas converter e data de saída campo.

Como converter e também substituir o formato da data para o mesmo arquivo?

Obrigado por qualquer ajuda.

Atenciosamente
  #2 (permalink)  
Old 11-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Localização: Sydney, Austrália
Posts: 1.009
awk's data e hora capacidades são limitadas, então eu normalmente uso perl quando manipular essas. Tente este:


Código:
perl -pe ' if ($_ =~ /.time.: ([0-9]+)L/) { s/$1L/scalar localtime/e; }' inputfile > outputfile

O formato de data não é muito o que você estava procurando, mas você pode fazer com alguns outros jiggery pokery strftime ou similar.
  #3 (permalink)  
Old 11-19-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderador
  
 

Join Data: dezembro 2003
Localização: Florida
Posts: 1.938
Outra maneira seria a de utilizar isto é tímido

Código:
gawk 'BEGIN { FS=","; OFS="," } {$7=" \47time\47: "strftime("%a %b %d %T", substr($7,10,10)); print }' file

  #4 (permalink)  
Old 11-19-2008
rk4k rk4k is offline
Usuário
  
 

Join Date: Nov 2008
Localização: / planet-earth/indonesia/jakarta /
Lugares: 11
Agradecimentos tanto para responder.

A solução é esfriar basbaque
Closed Thread

Marcadores

Tags
awk, sed, substituto

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 03:17.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0