Dear All,
Sorry to bother you. But I tried the below problem but didn't come up a good solution. A have a file containing such info
2009-03-14 22:01:01,430 :: [TID:568][REFID:09031422000000958][MNO:181][NW:AK][TT:472][INSTR:1237046400958][INEND:1237046401430]
2009-03-14 22:05:01,430 :: [TID:903][REFID:09031422000000958][MNO:458][NW:AK][STG:TOP][TT:572][INS:1237046400958][INEND:1237046401430]
I need to show simply
22:01:01, 568, 181, 472
22:05:01, 903, 458, 572
that is time, TID, MNO, TT
i tried it with
x=1;
while [ $x -le $linecount ]
do
singleline=`sed "${x}q;d" $inputfile`
dttime=`echo $singleline | cut -d "," -f 1`
singleline=`echo $singleline|cut -d "," -f 2|awk '{print $3}'`
echo $singleline|awk '{gsub("\\[|\\]",":");print}'|awk -F: '{print $dttime","$3","$9","$18}'
x=`expr $x + 1`
done
But it doesn't show the correct result. Would you please look?
# sed 's/[^ ]* \([^,]*\),.*TID:\([0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' infile
22:01:01, 568, 181, 472
22:05:01, 903, 458, 572
HTH
this solution is superb. but one problem in regular expression. that is if
TID:T009.998.3333 like this
then this code is not working?
then try like this..
sed 's/[^ ]* \([^,]*\),.*TID:\([0-9]*.[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file
sed 's/^.*\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*TID:\([0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*$/\1,\2,\3,\4/' filename
I don't know why it is not working. every thing is okay but ..
2009-03-14 22:00:03,420 :: [TID:F090314.20.209][REFID:09031422000200999][MNO:1812513180][NW:AK][STG:TOP][TT:420][INSTRTIME:1237046402999][INENDTIME:1237046403419]
2009-03-14 22:00:03,431 :: [TID:F090314.022.2021][REFID:09031422000300098][MNO:1817220980][NW:AK][STG:TOP][TT:332][INSTRTIME:1237046403098][INENDTIME:1237046403430]
sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file.txt
saifurshaon:
I don't know why it is not working. every thing is okay but ..
2009-03-14 22:00:03,420 :: [TID:F090314.20.209][REFID:09031422000200999][MNO:1812513180][NW:AK][STG:TOP][TT:420][INSTRTIME:1237046402999][INENDTIME:1237046403419]
2009-03-14 22:00:03,431 :: [TID:F090314.022.2021][REFID:09031422000300098][MNO:1817220980][NW:AK][STG:TOP][TT:332][INSTRTIME:1237046403098][INENDTIME:1237046403430]
sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file.txt
sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g'
you have inserted one extra * in that
not working
There is an Alphabet after TID:T
so is the sed command is rite one?
you want that T or not?? i thought you need that T
if not try this
sed 's/[^ ]* \([^,]*\),.*TID:[A-Z]\([0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' filename
Dear All,
Still I can't resolve this issue
The file's content is like this (there is 4 spaces after the variable followed by comma)
2009-03-14 22:00:03,420 :: [TID:F090314.20.209][REFID:09031422000200999][MNO:1812513180][NW:AK][STG:TOP][TT:420][INSTRTIME:1237046402999][INENDTIME:1237046403419]
2009-03-14 22:00:03,431 :: [TID:F090314.022.2021][REFID:09031422000300098][MNO:1817220980][NW:AK][STG:TOP][TT:332][INSTRTIME:1237046403098][INENDTIME:1237046403430]
This script is not showing the TID
sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file.txt
Would someone make the correction?
Okay at last i had the solution. I just put and it worked
sed 's/[^ ]* \([^,]*\),.*TID:\([A-Z][0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TTIN:\([0-9]*\).*/\1, \2, \3, \4/g'