LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-27-2016, 09:23 AM   #1
tgolden
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
#!/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
 
Old 03-27-2016, 11:13 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352
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}'
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 11:15 PM.
 
  


Reply


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 10:07 AM
[cygwin] How to use the cygwin.dll in Windows Programming Predatorian Programming 3 07-25-2014 11:45 AM
[SOLVED] BASH newb - how to loop and do a repetitive list of commands? pacorabanix Programming 5 10-04-2012 03:51 AM
Suse 9.1 Personal Reiserfs Transactional Log Error Rogern Linux - Newbie 1 10-11-2004 07:25 PM
how to log data to disk file mikesievers Programming 1 04-25-2002 01:36 PM


All times are GMT -5. The time now is 12:46 PM.

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