Sponsored Content
Full Discussion: Awk help needed
Top Forums UNIX for Dummies Questions & Answers Awk help needed Post 302365701 by mglenney on Wednesday 28th of October 2009 07:07:20 PM
Old 10-28-2009
Thanks for the nudge in the right direction. First off, I didn't know I could perform the calculation without removing the "K" from each number. That certainly saved some steps. Besides that, your rewrite allows me to fit it all in a single awk which makes outputting the number of lines easy. Here's what I came up with:

Code:
awk 'BEGIN { count=0 } NR > 10 && /Full GC/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++} END { print NR; print count }' testawk.data

The 'NR > 10' will actually be 'NR > lines' once I incorporate it into the script. You can see it in my first post. This allows me to skip over log file entries checked in previous runs of the script.

Thanks again

---------- Post updated 10-28-09 at 04:07 PM ---------- Previous update was 10-27-09 at 06:25 PM ----------

All is working well except I can't seem to pass the search string to awk. Here's the snippit:

Code:
set -- $(awk -v lines=$lineslastrun -v pattern="$searchpattern" '
  BEGIN { count=0 }
  NR > lines && /Full GC/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
  END { print NR; print count }
' $logfile)
totallines=$1
matches=$2

I would like to change "Full GC" to "pattern" so I can pass the string as a variable to awk. Unfortunately it only works if I put in as it is above. I have tried many versions of single and double quotes:

Code:
NR > lines && /pattern/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
NR > lines && "/pattern/",/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
NR > lines && /"pattern"/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}

Plus many more. None worked. Any suggestions?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk help needed.

Dear All, I want to compare column 3 and column 4 of files(File1 and File2) and want to get the matched records in one file and rejected records in another file.I have tried an awk script,but as Iam not good in it,I cant able to continue.Can anyone help me in this one. File 1... (0 Replies)
Discussion started by: cskumar
0 Replies

2. Shell Programming and Scripting

awk help needed

I am trying to write a script that will parse out the e-mail address of a person from the name of a file in a directory. Example: filename is: /home/myname/first.middle.last@email.com.xls I want to extract just the email address and mail the file to that address. I want to send the... (6 Replies)
Discussion started by: Drenhead
6 Replies

3. Shell Programming and Scripting

awk help needed

How do I alter this command so that it prints only the second comma delimited field from line number 3? Secondly, how do you redirect the output to a variable called TEST? Thanks (cat BATCH007.TXT | awk 'BEGIN { FS = "," } ; {print $2 }') (5 Replies)
Discussion started by: ddurden7
5 Replies

4. Shell Programming and Scripting

help needed in awk

Hi , i have a file a.txt like this: far near veryfar toonear typeset var1=veryfar to extract the text between two strings i use the following command : awk '/far/,$veryfar/' a.txt its not working can nyone tell pls whats wrong in it ? i doubt can we use variable in awk like this... (3 Replies)
Discussion started by: santosh1234
3 Replies

5. Shell Programming and Scripting

Awk Help needed

hi, I have input file woth records as shown below OCSMRC_OK,7057348733,+0.00,0,18/05/2010 23:42:19,BellMobility,302610000918553,0006056099,B30,686505,686505,OCS_MRC,+49.14,0,0 ,0,0, OCSPPKB_NOK,4163460120,+1.25,0,18/05/2010... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

6. UNIX for Dummies Questions & Answers

help needed for awk

Dear all, I am new to use unix. I run the following command and got the error. Anyone knows how should I modify the command. Thanks a lot! $ for chr in 'seq 1 23'; do awk 'BEGIN {print "T","pheno";}{print "M",$2}' out_${chr}.map > dat_${chr}.dat; done error message:... (2 Replies)
Discussion started by: forevertl
2 Replies

7. Shell Programming and Scripting

awk help needed

Hi, i have input records as shown below. 4097,Probe3,G10,255,05/17/2011 12:44:03:185,NULL,05/17/2011 12:39:03:180,05/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

8. Shell Programming and Scripting

awk help needed

Hi Experts, I have a file (file 1) with several columns and I need to create 2 files based on the data of 20th column of file 1. Criteria 1 : If the 20th field of file1 is empty , copy the entire records to file 2. I am successfully able to do this with the following awk code : awk... (2 Replies)
Discussion started by: nua7
2 Replies

9. Shell Programming and Scripting

awk help needed

Hi Everyone, i have following in my file 1 2 3 4 5 6 . . 100 and now i want the output as 1 4 7 ..........so on..............97 100 (10 Replies)
Discussion started by: zozoo
10 Replies

10. Shell Programming and Scripting

awk - help needed please

Hi.. have a file as below, appreciate if someone can help on this 143|500| 10| 23353 22131 23355 23354 23358 23352 23357 23350 23349 23351| RAID5 213|1008| 9| 22419 22412 221 22413 22414 22416 22417 22415 22418| RAID6 1088|500| 5| 22243 22240 22244 22242 22241| RAID5 322|1200| 12|... (6 Replies)
Discussion started by: richard0@rediff
6 Replies
log(8)							      System Manager's Manual							    log(8)

NAME
log - Records input and output from a program SYNOPSIS
/usr/sbin/log <logfile> <command> OPERANDS
The file in which to record the interaction being logged. The command to execute. DESCRIPTION
The log program runs <command> and logs the input to and output from <command> to the <logfile> file. Input and output are logged until <command> exits, the log program exits, and the exit status of <command> is returned. The log program is used by the system installation procedure and the it(8) command to create the /var/adm/smlogs/install.log and /var/adm/smlogs/it.log installation log files. RESTRICTIONS
Because the log program is used in the installation standalone environment, program size was the greatest concern in its implementation. The log program does not search for the PATH variable to locate <command> and error messages are terse. The log program causes <command> to take standard input from and write standard output and standard error to UNIX pipes. Some commands will not be able to operate in this environment; therefore, it is suggested that you use the script(1) command instead. UNIX shells will not issue prompts when run from log unless the shell is started with an explicit interactive switch (-i for most shells). For example, log foo.tmp /sbin/sh -i In the previous example, foo.tmp is the name of <logfile>. The log program intercepts end-of-file (usually Ctrl/d). Therefore programs which normally receive end-of-file as an exit command must exit by some other means. ERRORS
Log open error Explanation: The log program was unable to open <logfile>. Verify that the directory exists and that ownerships and permissions are set correctly. Exec Error Explanation: The log program was unable to execute <command>. Verify that you specified a full pathname for <command> and that <command> is an exe- cutable file. Fork Error Explanation: The log program was unable to create one of the processes it requires to log data. SEE ALSO
Commands: it(8), script(1) log(8)
All times are GMT -4. The time now is 10:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy