Issue with awk command


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Issue with awk command
# 1  
Old 07-21-2017
Issue with awk command

I am new to unix.I have a requirement to get few fields from the log file as below.

Log
Code:
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

Code:
awk -F 'Points balance from MIS for user with|(VAROrderManager)|' '{print $2}' rbcdup.txt

Output

Code:
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

Code:
userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is 99243

How can this be achieved.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!


---------- Post updated at 12:21 AM ---------- Previous update was at 12:06 AM ----------

Log
Code:
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

Code:
awk -F 'Points balance from MIS for user with|(VAROrderManager)|' '{print $2}' rbcdup.txt


Last edited by RudiC; 07-21-2017 at 02:27 AM.. Reason: Added CODE tags.
# 2  
Old 07-21-2017
Welcome to the forum.

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:
Code:
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

This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-21-2017
Appreciate your help,it worked

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.
Code:
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

Code:
awk 'BEGIN{ OFS="|"; print "Column1|Column2|Column3|Column4|Column5|Column6"};
> NR > 1{print $4, $4, $6, $7, $8, $9;}' file.txt > file.xls

The excel is generated but not in proper format.
1. All headers came in one column
2. The space in the .txt file has occupied in excel with many cells having |
3. The last column is not displayed with value.Ex 5195,3631 etc

Code:
Column1|Column2|Column3|Column4|Column5|Column6
|||||
name:|LENORE|and|last|name:|HARDER
|||||
|||||
|||||
name:|YITZCHOK|and|last|name:|PLOPPER
|||||
|||||
|||||
name:|IGOR|and|last|name:|REVA

Can the shell convert the txt into excel.any links available further on this.Thanks.

The desired output is as follows in xcel

Code:
UserID     First name   Lastname   Points
8604826  SUSAN         PAICE        5195


Last edited by Scrutinizer; 07-21-2017 at 05:12 PM.. Reason: Query to convert into excel; [mod] Added code tags
# 4  
Old 07-21-2017
Try:
Code:
awk -F'^.*user with |: |, | (and|is) | [(]' '
  NF<8 {
    next
  } 
  NR==1 {
    print $2, $4, $6, "Points"
  }
  {
    print $3, $5, $7, $8}
' OFS=\| file

Output:
Code:
userId|first name|last name|Points
19651069|DEREK RICHARD|BOUDREAU|99243
8604826|SUSAN|PAICE|5195

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with awk command between Linux and Solaris

Hi, Here is the output using bash profile on Linux uptime 04:59:14 up 16 days, 4:48, 2 users, load average: 1.00, 1.00, 1.20 Here is the output using bash profile on Solaris uptime 4:00am up 84 day(s), 22:21, 3 users, load average: 0.09, 0.10, 0.12 Now,... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. UNIX for Beginners Questions & Answers

awk command issue

Hi All, I am trying to perform certain task using awk command but the command is not returning expected output though it is running fine independently but not in for loop. req: 1. I am searching a pattern (say pattern1) in a dated file 2. trying to search the last occurrence of the another... (11 Replies)
Discussion started by: abhii
11 Replies

3. Shell Programming and Scripting

awk command issue

Hi All, I have one file with below content Post1:uri Post2:urieop Post3:urtei I am trying to read each word seprated by delimiter with below command Value1=$(awk -F":" '{print $1}' $HSFILE) Value2=$(awk -F":" '{print $2}' $HSFILE) echo $Value1 echo $Value2 It is... (5 Replies)
Discussion started by: sharsour
5 Replies

4. Shell Programming and Scripting

For loop, awk command issue

limit.csv data -------------- 5600050 38Nhava 400077 27Bomay rate.txt data ------------- 38NhaVA 27BomaY 27Bomay below is my script: for i in `cat limit.csv` do b=`awk '{print $1}' $i` (4 Replies)
Discussion started by: p_satyambabu
4 Replies

5. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

6. Shell Programming and Scripting

awk issue

Hi all, i am trying to use below command to see the output of hardware inventory, but i only see 2 first line no output of the command. awk '/Hardware/ {print $0}' XXX_result.txt Hardware inventory: Hardware inventory: any idea how to see whatever is under hardware inventory. i... (11 Replies)
Discussion started by: Jared
11 Replies

7. Shell Programming and Scripting

awk NR issue

Hi guys, i am trying to analyze a text file using awk and am not able to solve this issue. This is the piece of code that I have written BEGIN { ## Time to count MACs -> 5 seconds. TIME_LIMIT = 5; k = 50000; } ## For every line. { time_in_seconds = $1... (2 Replies)
Discussion started by: jamie_123
2 Replies

8. Shell Programming and Scripting

awk command issue

Hi, Please could someone advise the issue i have with my awk command ? my command is : export NUM_SCENARIOS=`awk -F= '!/^#/ && /NUM_SCENARIOS/{print $2}' /home/environment.properties` when I echo $NUM_SCENARIOS this comes back with : 100 10 The issue I have is, there is... (9 Replies)
Discussion started by: venhart
9 Replies

9. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

10. Shell Programming and Scripting

command line arg issue with awk

Hi friends, I am trying to pass input from command line and trying to print that column values. (FYI: I am using ksh) My code goes like this... #!/bin/sh column=$1 awk '{print $'$column'}' I execute using command like this --> ls -l | file_name parameter Hope I am clear with my... (2 Replies)
Discussion started by: divzz
2 Replies
Login or Register to Ask a Question