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

时间:2014-05-23 08:33:07

标签: bash unix shellcode logfile

我有一个特定的应用程序数据库文件,如下所示:

    •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可以打开这些文件。

2 个答案:

答案 0 :(得分:5)

使用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

答案 1 :(得分:4)

你可以试试这个:

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  

你在前一行有问题,但我不知道是否可以。 我不知道你想要对齐你的等等......