I have a log file like this. I don't want to fetch the accounts that were previously fetched at like 09:28
Connected to feeder version 2.1 09:28:30 29/03/2014 Loading Account 01234567EUR
09:28:30 29/03/2014 Loading Account 0123456755JPY
09:28:30 29/03/2014 Loading Account 0123426567INR
09:28:30 29/03/2014 Loading Account 012345698887USD
09:28:30 29/03/2014 Loading Account 012343422567EUR
09:28:30 29/03/2014 Account 0234456783388KRY not set up
09:28:30 29/03/2014 Account 0234454467888CNH not set up
09:28:30 29/03/2014 Error : Closing Balance of Account 02344567888GBP Doesn't match
Connected to feeder version 2.1 09:28:30 29/03/2014 Loading Account 01234567EUR
10:28:30 29/03/2014 Loading Account 012343356755GBP
10:28:30 29/03/2014 Loading Account 012342654467INR
10:28:30 29/03/2014 Loading Account 01234564498887USD
10:28:30 29/03/2014 Loading Account 01234663422567EUR
10:28:30 29/03/2014 Account 02344567833886KRY not set up
10:28:30 29/03/2014 Account 023445446788866CNH not set up
10:28:30 29/03/2014 Error : Closing Balance of Account 02344567888GBP Doesn't match
Now i used the following sed command to fetch the error accounts
sed -n "
s/.* Closing Balance of Account \(.*\) Doesn't match/\1/p;
s/.* Account \(.*\) not set up/\1/p
"
But How to extract only the new accounts. For eg i don't want accounts extratced at 9.28 again to come at 10.28 list. Thanks in advance for your help
You can store most recent timestamp in a separate file and pass it back to sed:
s='09:28'
sed -n "/^$ts/"'!{s/.* Closing Balance of Account \(.*\) Doesn.t match/\1/p; s/.* Account \(.*\) not set up/\1/p;}' file
02344567833886KRY
023445446788866CNH
02344567888GBP
EDIT: To store latest timestamp in a file use:
tail -1 file | egrep -o '^[0-9]+:[0-9]+' > tmp.txt
And use this value:
s=$(<tmp.txt)
sed -n "/^$ts/"'!{s/.* Closing Balance of Account \(.*\) Doesn.t match/\1/p; s/.* Account \(.*\) not set up/\1/p;}' ff
Assuming that you want the lines after the last "Connected to feeder" line: Read the file backwards; print each line until you come to the indicated pattern; re-reverse the lines; search for the account ids:
tac logfile |
awk '/^Connected to feeder/ {exit} 1' |
tac |
grep -oP '(Closing Balance of )?Account \K\w+(?= not set up| Doesn)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With