如何从bash中的特定应用程序数据库文件创建日志文件?

问题描述:

我有一个特定的应用程序的数据库文件是这样的:如何从bash中的特定应用程序数据库文件创建日志文件?

 
    •r   vbc.vvc   lin    K$³ñ123456 Œ Œ  P 


         P  P       ;šÉÿ             ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ   ÿÿÿÿ        Œ ÿÿÿÿ   Œ  P T X 
     Œ    P 999999999 ëu q0 …ª¤  ;šÉÿOverLimitLog  ÿÿ 06/27/2013 00:05:55 RS_A1_6   hijitso   183.49 OverLow   ÿÿ 06/27/2013 00:16:30 qaser   hijitso   993.08 hffvcgcf   ÿÿ 06/27/2013 00:18:46 yuikl   hijitso   993.08 hffvcgcf   ÿÿ 06/27/2013 00:25:01 gcxsd   hijitso   999.18 hffvcgcf   ÿÿ 06/27/2013 00:40:45 hgdrt   sdfcdsfb    0.00 Normal   ÿÿ 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfa    13.13 hasfldkdgh  ÿÿ 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfc    13.13 hasfldkdgh  ÿÿ 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfb    13.13 hasfldkdgh  ÿÿ 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfa    0.00 Normal   ÿÿ 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfc    0.00 Normal   fhfx 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfb    0.00 Normal   ÿÿ 06/27/2013 06:28:05 khuhukjmnj,l  sdfcdsfa    10.79 hasfldkdgh  ÿÿ 06/27/2013 06:28:05 khuhukjmnj,l  sdfcdsfc    10.79 hasfldkdgh  ÿÿ 06/27/2013 06:30:05 khuhukjmnj,l  sdfcdsfc    9.38 hasfldkdgh  ÿÿ 06/27/2013 06:30:05 khuhukjmnj,l  sdfcdsfb    9.38 hasfldkdgh  ÿÿ                     ÿÿ                     ÿÿ                     ÿÿ                     ÿÿ                     ÿÿ    

我想将其转换为这种格式:

06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfc    0.00 Normal 

我必须说,我的文件不是一个普通的文本格式,并在gedit中打开时有一些不可读的字符,但emacs23可以打开这些文件。

+1

这可能是最好的检查如何生成此文件。 – fedorqui

+0

我不知道为什么日志文件出现在6行中。 –

+0

它是一个应用程序数据库。该软件可以读取它并在其内部显示 – user3121138

随着GNU awk的,你可以做这样的事情:

$ awk 'NR>1{print RS, $1, $2, $3, $4, $5, $6}' RS='fhfx' OFS='\t' file 
fhfx 06/27/2013 00:05:55 RS_A1_6 hijitso 183.49 OverLow 
fhfx 06/27/2013 00:16:30 qaser hijitso 993.08 hffvcgcf 
fhfx 06/27/2013 00:18:46 yuikl hijitso 993.08 hffvcgcf 
fhfx 06/27/2013 00:25:01 gcxsd hijitso 999.18 hffvcgcf 
fhfx 06/27/2013 00:40:45 hgdrt sdfcdsfb 0.00 Normal 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfa 13.13 hasfldkdgh 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfc 13.13 hasfldkdgh 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfb 13.13 hasfldkdgh 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfa 0.00 Normal 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfc 0.00 Normal 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfb 0.00 Normal 
fhfx 06/27/2013 06:28:05 khuhukjmnj,l sdfcdsfa 10.79 hasfldkdgh 
fhfx 06/27/2013 06:28:05 khuhukjmnj,l sdfcdsfc 10.79 hasfldkdgh 
fhfx 06/27/2013 06:30:05 khuhukjmnj,l sdfcdsfc 9.38 hasfldkdgh 
fhfx 06/27/2013 06:30:05 khuhukjmnj,l sdfcdsfb 9.38 hasfldkdgh 

或者,如果你想让它更漂亮,你可以使用column

$ awk 'NR>1{print RS, $1, $2, $3, $4, $5, $6}' RS='fhfx' file | column -t 
fhfx 06/27/2013 00:05:55 RS_A1_6  hijitso 183.49 OverLow 
fhfx 06/27/2013 00:16:30 qaser   hijitso 993.08 hffvcgcf 
fhfx 06/27/2013 00:18:46 yuikl   hijitso 993.08 hffvcgcf 
fhfx 06/27/2013 00:25:01 gcxsd   hijitso 999.18 hffvcgcf 
fhfx 06/27/2013 00:40:45 hgdrt   sdfcdsfb 0.00 Normal 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfa 13.13 hasfldkdgh 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfc 13.13 hasfldkdgh 
fhfx 06/27/2013 06:25:55 khuhukjmnj,l sdfcdsfb 13.13 hasfldkdgh 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfa 0.00 Normal 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfc 0.00 Normal 
fhfx 06/27/2013 06:27:16 khuhukjmnj,l sdfcdsfb 0.00 Normal 
fhfx 06/27/2013 06:28:05 khuhukjmnj,l sdfcdsfa 10.79 hasfldkdgh 
fhfx 06/27/2013 06:28:05 khuhukjmnj,l sdfcdsfc 10.79 hasfldkdgh 
fhfx 06/27/2013 06:30:05 khuhukjmnj,l sdfcdsfc 9.38 hasfldkdgh 
fhfx 06/27/2013 06:30:05 khuhukjmnj,l sdfcdsfb 9.38 hasfldkdgh 
+0

非常好的答案!我爱bash。 – Thibault

+0

现在我该如何启动数据线? – user3121138

+0

我的真实文件有“ÿÿ”字符。在“ÿÿ”之前,我有管道字符,但没有在这里显示。第二个问题:我如何从我的文件中删除该文件? – user3121138

你可以试试这个:

cat output.txt | sed 's/fhfx/\n&/g' | sed 's/ÿÿ *//g' | sed '/fhfx/!d' 

其结果是:

 
fhfx 06/27/2013 00:05:55 RS_A1_6   hijitso   183.49 OverLow   
fhfx 06/27/2013 00:16:30 qaser   hijitso   993.08 hffvcgcf   
fhfx 06/27/2013 00:18:46 yuikl   hijitso   993.08 hffvcgcf   
fhfx 06/27/2013 00:25:01 gcxsd   hijitso   999.18 hffvcgcf   
fhfx 06/27/2013 00:40:45 hgdrt   sdfcdsfb    0.00 Normal   
fhfx 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfa    13.13 hasfldkdgh  
fhfx 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfc    13.13 hasfldkdgh  
fhfx 06/27/2013 06:25:55 khuhukjmnj,l  sdfcdsfb    13.13 hasfldkdgh  
fhfx 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfa    0.00 Normal   
fhfx 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfc    0.00 Normal   
fhfx 06/27/2013 06:27:16 khuhukjmnj,l  sdfcdsfb    0.00 Normal   
fhfx 06/27/2013 06:28:05 khuhukjmnj,l  sdfcdsfa    10.79 hasfldkdgh  
fhfx 06/27/2013 06:28:05 khuhukjmnj,l  sdfcdsfc    10.79 hasfldkdgh  
fhfx 06/27/2013 06:30:05 khuhukjmnj,l  sdfcdsfc    9.38 hasfldkdgh  
fhfx 06/27/2013 06:30:05 khuhukjmnj,l  sdfcdsfb    9.38 hasfldkdgh 

您在最后一行有问题,但我不知道它是否正常。 我不知道你想对齐你的列等...

+0

你不需要猫,因为sed会在命令行上接受文件名 - 参见UUOC – Iain

+0

@Iain是的,但是那是一个例子,因为我不知道什么是日志文件的来源。也许他想“尾巴”,或者这是其他命令的结果。 – Thibault