I am new to unix.I have a requirement to get few fields from the log file as below.
Log
app9/cc-gr_base.log.2017-07-19.gz:[2017-07-19 23:59:20,352] hostname 1500523166993 NA:NA:NA http-nio-8080-exec-56 INFO Points balance from MIS for user with userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243 (VAROrderManager)
app9/cc-gr_base.log.2017-07-19.gz:[2017-07-19 23:40:44,921] app9.aplprd.bridge2solutions.net 1500522052487 NA:NA:NA http-nio-8080-exec-53 INFO Points balance from MIS for user with userId: 8604826, first name: SUSAN and last name: PAICE is 5195 (VAROrderManager)
Have written the below command
awk -F 'Points balance from MIS for user with|(VAROrderManager)|' '{print $2}' rbcdup.txt
Output
userId: 8604826, first name: SUSAN and last name: PAICE is 5195 (
userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243 (
Now the issue is am getting left bracket ( in the output. My intention is to get only
userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243
How can this be achieved.
---------- Post updated at 12:21 AM ---------- Previous update was at 12:06 AM ----------
Log
app9/cc-gr_base.log.2017-07-19.gz:[2017-07-19 23:59:20,352] hostname 1500523166993 NA:NA:NA http-nio-8080-exec-56 INFO Points balance from MIS for user with userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243 (VAROrderManager)
app9/cc-gr_base.log.2017-07-19.gz:[2017-07-19 23:40:44,921] app9.aplprd.bridge2solutions.net 1500522052487 NA:NA:NA http-nio-8080-exec-53 INFO Points balance from MIS for user with userId: 8604826, first name: SUSAN and last name: PAICE is 5195 (VAROrderManager)
Code
awk -F 'Points balance from MIS for user with|(VAROrderManager)|' '{print $2}' rbcdup.txt
As parentheses have a special meaning in regular expressions, you need to escape them, in this case and on my system with TWO back slashes: \\(
Is it possible to allow for a wildcard: .VAROrderManager. ?
Or use a different approach:
awk 'gsub (/^.*user with |.VAROrderManager.*$/, _)' file1
userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243
userId: 8604826, first name: SUSAN and last name: PAICE is 5195
The output is now properly obtained as below with spaces .This is expected as there are few other statements in the parent log which doesnot match the criteria.
userId: 5220818, first name: JOAN and last name: CHARLES is 23063
userId: 8604826, first name: SUSAN and last name: PAICE is 5195
userId: 17064784, first name: RAFAEL ALFONSO and last name: FABREGAS is 31970
userId: 21930053, first name: AERRON and last name: GALANG is 3631
userId: 8604826, first name: SUSAN and last name: PAICE is 5195
My next requirement was to make this .txt file to excel.On searching the forum i wrote the below code