Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-27-2016, 08:23 AM   #1
LQ Newbie
Registered: Oct 2015
Posts: 1

Rep: Reputation: Disabled
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
set -x
echo "what is the input file"
read f

for value in $f
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
Old 03-27-2016, 10:13 PM   #2
Senior Member
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,603

Rep: Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509
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:
awk '/traceuid/ {print $5,$6}'
would select lines containg the string 'traceuid' and print just the fifth and sixth fields delimited by space characters. (You do not need "-F ' ' " option to awk as it is the default.)
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.

Last edited by allend; 03-27-2016 at 10:15 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cygwin, emacs and associate it with a file type on Windows .. susja Linux - Newbie 2 07-11-2015 09:07 AM
[cygwin] How to use the cygwin.dll in Windows Programming Predatorian Programming 3 07-25-2014 10:45 AM
[SOLVED] BASH newb - how to loop and do a repetitive list of commands? pacorabanix Programming 5 10-04-2012 02:51 AM
Suse 9.1 Personal Reiserfs Transactional Log Error Rogern Linux - Newbie 1 10-11-2004 06:25 PM
how to log data to disk file mikesievers Programming 1 04-25-2002 12:36 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration