cannot loop through log file with repetitive transactional data using cygwin on windows 7
I have a log file with transactional data of about 1800 transactions delimited by "<<< doInit" to start each transaction and ">>> processRequest" to end each transaction with no spaces between transactions.I need to be able to separate and parse out specific values for each transaction. The script below I am using will only find the first transaction. How do i tell the script, I want to run a set of commands on all 1800 transactions individually.
$ cat readscript #!/usr/bin/sh set -x echo "what is the input file" read f for value in $f do t=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 traceuid | awk -F ' ' '{print $5,$6}' | sed -n '2p' | cut -c 11-` tx=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 transactionid | awk -F ' ' '{print $1,$2,$5,$6}' | sed -n 3p` r=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 retailername | awk -F ' ' '{print $1,$2,$5,$6}' | sed -e '$!{h;d;}' -e x` rc=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 responsecode | awk -F ' ' '{print $1,$2,$5,$6}' | sed -n '3p'` time=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 datetime | sed -n '3p'` tt=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 milli | sed -n '2p' | awk -F ' ' '{print$11}'` ra=`cat $f | tr '<' '\n' | tr '>' '\n' | egrep -i -B1 path | sed -n '2p' | awk -F ' ' '{print$6}' | cut -c 6-` echo 'TraceUID='$t, 'TransactionID='$tx, 'RetailName='$r, 'ResponseCode='$rc, 'Merchanttime='$time, 'totalmillisec='$tt, 'requestaction='$ra>> script1out.txt 2>&1 done |
Welcome to LQ!
When posting code at LQ, please use [CODE][/CODE] tags around the code. It improves readability and maintains white space. I think you need to study awk a little more. What you are doing with 'cat', 'tr', 'egrep', 'sed' and 'cut' can all be done within awk. For example: Code:
awk '/traceuid/ {print $5,$6}' Where you have used 'cut', look at 'substr' in awk. If you want further help, posting a sample of the data, suitably redacted for privacy, would be of benefit. |
All times are GMT -5. The time now is 04:08 AM. |