1

I have a log file which somewhat looks like this

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

I want to extract the account numbers where there is a closing balance mismatch or if the account is not set-up and put those accounts into a new file for my further processing.The first step is i have used grep -il 'not set up' but after that how do I extract the account numbers, The pattern seems to be very random(not sure if I can use awk based on delimeter) Only pattern that is for sure is last 3 characters of an account Number is currency. So is it possible to use egrep and regex for this. Thanks

0

4 Answers 4

2

Here is one way with awk:

$ awk '
/not set up/ {
    for(i=1;i<=NF;i++) 
        if($i~/Account/) print $(i+1)":Not Set Up" > "Review.txt"
}
/Error/ {
    for(i=1;i<=NF;i++)
        if($i~/Account/) print $(i+1)":Mismatch" > "Review.txt"
}' file

This creates the following file:

$ cat Review.txt
0234456783388KRY:Not Set Up
0234454467888CNH:Not Set Up
02344567888GBP:Mismatch
Sign up to request clarification or add additional context in comments.

1 Comment

Tanks a lot for your answer, works like a charm.I was about to make this more complicated by using egrep and ending up nowhere.
2

I'd use sed, without grep:

sed -n "
    s/.* Closing Balance of Account \(.*\) Doesn't match/\1/p;
    s/.* Account \(.*\) not set up/\1/p
  "

Adjust to taste, e.g. if you want to print something next to either case to identify which accounts have which problem.

1 Comment

Thanks a lot for your answer, works superb. Basically these are the sub-account numbers which I have to lookup in the database and get the main account numbers and then add a comment/Reason.
1

You can use the grep statements as follows to get the desired account numbers:

grep 'not set up' file.txt | grep -Po '\d+[A-Z]{3}'
grep 'Error' file.txt | grep -Po '\d+[A-Z]{3}'

Comments

1

Another way, shortish from the command line, just the account numbers:

awk -F'^.*Account|[ \t]*' '/Error|set/{print $3}' file

Or together with the reason:

awk -F'^.*Account[ \t]*' '!/Loading/{print $2}' file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.