Aswex
March 17, 2011, 8:53am
1
Hello,
I need help to format a log file...again ; ))
Here is what I have :
FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ ';;
ARC_DATE='2011-01-21'
ARC_TIME='00.10.12'
;;
STAS034 RC = 0 I Deroulement correct
*****
here is what i need :
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ /OPERATIONNEL/SATURNE/MASTER
I need date<tab>filename<tab>path
tahnks for your help.
---------- Post updated at 06:23 AM ---------- Previous update was at 06:00 AM ----------
Here is what I've done so far :
I have the ouput in one ligne with space tab between :
sed -n "/^FILE/{N;s/FILE='//;s/ .*\n ARC_DATE='/ /;s/'$//;s#\(.*\)/#\1 #;p;}" infile
/OPERATIONNEL/SATURNE/MASTER SATURNE_MASTER_PRE_R20110119.TAR.GZ 2011-01-21
but how to format the ligne as wanted
date<tab>filename<tab>path
thanks
---------- Post updated at 07:53 AM ---------- Previous update was at 06:23 AM ----------
Hello I've found a way to do it with nawk :
| nawk -F" " '{ print $3" "$2" "$1 }'
problem solved.
Thanks
ctsgnb
March 18, 2011, 10:39am
2
could be done within one sed like
# sed -n "/^FILE/{N;s/\n/ /g;s:[^']*'\(/.*\)/\([^/ ]*\)[^']*'[^']*'\([^']*\)':\3 \2 \1:p}" infile
or
# sed -n "/^FILE/{N;s:.*='\(.*\)/\([^ ]*\) .*\n.*='\(.*\)'$:\3 \2 \1:;p}" tst
# cat tst
FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ ';;
ARC_DATE='2011-01-21'
ARC_TIME='00.10.12'
;;
STAS034 RC = 0 I Deroulement correct
*****
# sed -n "/^FILE/{N;s/\n/ /g;s:[^']*'\(/.*\)/\([^/ ]*\)[^']*'[^']*'\([^']*\)':\3 \2 \1:p}" tst
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ /OPERATIONNEL/SATURNE/MASTER
#
# sed -n "/^FILE/{N;s:.*='\(.*\)/\([^ ]*\) .*\n.*='\(.*\)'$:\3 \2 \1:;p}" tst
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ /OPERATIONNEL/SATURNE/MASTER
1 Like
# cat file
FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ
ARC_DATE='2011-01-21'
ARC_TIME='00.10.12'
;;
STAS034 RC = 0 I Deroulement correct
*****
# sed -n "N;s/\n//;s/.*='\/\(.*\)\/\(.*\) .*='\(.*\)'/\3 \2 \/\1/p" file
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ /OPERATIONNEL/SATURNE/MASTER
1 Like
ctsgnb
March 18, 2011, 12:48pm
4
@ygemici
But should work if more than one line starting with FILE ... by the way, you also shouldhandle the blank space (between the end of the file name and the trailing ';;
# cat tst
FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ ';;
ARC_DATE='2011-01-21'
ARC_TIME='00.10.12'
;;
STAS034 RC = 0 I Deroulement correct
*****
# sed -n "/^FILE/{N;s:.*='\(.*\)/\([^ ]*\) .*\n.*='\(.*\)':\3 \2 \1:p}" tst
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ /OPERATIONNEL/SATURNE/MASTER
your code gave (on a linux machine) :
# sed -n "N;s/\n//;s/.*='\/\(.*\)\/\(.*\) .*='\(.*\)'/\3 \2 \/\1/p" tst
2011-01-21 SATURNE_MASTER_PRE_R20110119.TAR.GZ ';; /OPERATIONNEL/SATURNE/MASTER
#
ctsgnb
March 19, 2011, 5:07pm
6
@Ygemici
No pb dude, in fact when i've read this thread for the first time, i also missed it !