Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The individual awk command works fine but when combined together getting a blank result. How can the script be improved to get the desired results.Please assist.
Thanks for the quick response.I forget to mention that i have initially written the below condition higlighted in the script, which resulted in getting the below results.
VarId programId participantId participantFirstName participantLastName email ipAddress UScode Shipping Number
This worked, but i am unable to understand the logic inside the code.Could you please explain for the reference.Again much thanks for the work around.
{ MAIN=$2" %DFAD% "$12" "$14" "$16" "$18" "$22" "$24 ; } /Decision from API: DECLINED/ { split($4, aFOUR, "[ :]"); sub("%DFAD%", aFOUR[4], MAIN); print MAIN;}' | uniq >poc.txt
Your log file put information you need in 1 line on 2 lines, which are not close to each other.
There is 2 parts, each start with :
Code:
/blahblah/ { foobar }
Awk applies 'foobar' only for lines with in 'blahblah'.
So with the first part :
Code:
/API fraud detection is enabled/ {...}
This part deal with the first line, the main one, with most information.
It builds one string (MAIN) with all possibles information, formatted as you want where you want.
As the missing information is in the middle, temporally, it puts the missing one as '%DFAD%'.
So when it leaves this part, you have a string like that : 2018-08-15 21:15:03 %DFAD% FF_CC 6980771296 Meryl Stout xx@GMAIL.COM xx.xx.xx.xx (xx) xx-xx
But it do not print it for you to see.
The second part, starting :
Code:
/Decision from API: DECLINED/ {...}
The first thing is to get the missing information.
Code:
split($4, aFOUR, "[ :]");
The field separators did not change, so we still use '][,='. The missing information is in $4 field. To get it, it split $4 into an array using '<space>' and ':' as separators. So what you want is in the 4th array's cell.
It replace '%DFAD%' by the 4th array's cell into the main string.
And as the lines are in order and it has all information you want, it prints the result : 2018-08-15 21:15:03 Delta FF_CC 6980771296 Meryl Stout xx@GMAIL.COM xx.xx.xx.xx (xx) xx-xx
This worked, but i am unable to understand the logic inside the code.Could you please explain for the reference.Again much thanks for the work around.
{ MAIN=$2" %DFAD% "$12" "$14" "$16" "$18" "$22" "$24 ; } /Decision from API: DECLINED/ { split($4, aFOUR, "[ :]"); sub("%DFAD%", aFOUR[4], MAIN); print MAIN;}' | uniq >poc.txt
Once more, please put your code inside [CODE] (via the sharp sign icon in the editor). You can edit your previous posts with the "Edit" button at the bottom right of your own each post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.