How can I make a log file from a specific application database file in bash?

I have a specific application database file, for example:

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


                        PP; šÉÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿ Œ ÿÿÿÿ Œ PTX  
      Œ 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 khuhukjdsj, l 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, sdfcdsfa 0.00 Normal ÿÿ 06/27/2013 06:27:16 khuhukjmnj, l sdfcdsfc 0.00 Normal fhfx 07/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 khuhuk l sdfcdsfb 9.38 hasfldkdgh ÿÿ ÿÿ ÿÿ ÿÿ ÿÿ ÿÿ               

I want to convert it to this format:

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

I have to say that my file is NOT a plain text format and it has an unreadable character when it opens in gedit, but emacs23 can open these files.

+4
source share
2 answers

With GNU awk, you can do something like this:

$ 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

Or, if you want it more beautiful, you can use 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
+5
source

You can try the following:

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

Result:

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  

, , . , ..

+4

Source: https://habr.com/ru/post/1541733/


All Articles