another vexing awk problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting another vexing awk problem
# 1  
Old 12-18-2011
another vexing awk problem

Hello;

I have the following commnad:

Code:
ls -lrt /ulogs/dblocks_logs/*log |awk '{print "grep Total "$9" |tail -20"}' | sh
05/10/11  21:54:01  Total number of locks:0
05/10/11  21:55:01  Total number of locks:0
05/10/11  21:56:01  Total number of locks:2
05/10/11  21:57:00  Total number of locks:0
05/10/11  21:58:00  Total number of locks:0
05/10/11  21:59:00  Total number of locks:3
05/10/11  22:00:00  Total number of locks:4
05/10/11  22:01:00  Total number of locks:4
05/10/11  22:02:01  Total number of locks:3
05/10/11  22:03:00  Total number of locks:2
05/10/11  22:04:00  Total number of locks:3

if the command :
Code:
ls -lrt /ulogs/dblocks_logs/*log

returns multiple logs, I need to find a way to echo the name of the log
before the grep output begins ..

I just can not think of a way

Any help is appreciated, Thank you
# 2  
Old 12-18-2011
Try this:

Code:
for file in $(ls -rt /ulogs/dblocks_logs/*log 2> /dev/null )
do
    echo "File: $file"
    grep Total $file | tail -20
done

# 3  
Old 12-19-2011
I tried this:

Code:
 ls -lrt /ulogs/dblocks_logs/*log |(awk '{print $9}'; awk '{print "grep Total "$9" |tail -20"}' | sh)

But it only gave log file names, NOT the grep output
# 4  
Old 12-19-2011
Try
Code:
awk '/Total/ {print FILENAME FS $0}' /ulogs/dblocks_logs/*log

# 5  
Old 12-19-2011
Code:
Log Name: /ulogs/dblocks_logs/rjl.db_locks.log
05/10/11  22:09:01  Total number of locks:1
05/10/11  22:10:01  Total number of locks:2
05/10/11  22:11:01  Total number of locks:2
05/10/11  22:12:00  Total number of locks:2
05/10/11  22:13:01  Total number of locks:1
Log Name: /ulogs/dblocks_logs/rjl.db_locks_exc2.log
12/19/11  09:50:00  Total number of locks:1
12/19/11  09:51:01  Total number of locks:5
12/19/11  09:52:01  Total number of locks:1
12/19/11  09:53:01  Total number of locks:9
12/19/11  09:54:00  Total number of locks:1
Log Name: /ulogs/dblocks_logs/rjl.db_locks_exc2sm.log
12/19/11  09:50:01  Total number of locks:1
12/19/11  09:51:01  Total number of locks:1
12/19/11  09:52:02  Total number of locks:1
12/19/11  09:53:02  Total number of locks:1
12/19/11  09:54:01  Total number of locks:2

This was the output I was looking for using " AWK "
# 6  
Old 12-19-2011
Code:
awk 'FNR==1 {print FILENAME} /Total/' /ulogs/dblocks_logs/*log

but note that this (and Chubler_XL's solution) will print the filename for every *log file, not just ones with matching lines.
# 7  
Old 12-19-2011
Thank you CarloM

But I need to tail the last 20 or whatever number of lines from each log file..
Is there a way to amend your awk command to do that ??
Otherwise it's great

Thnx again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk-if problem

Hi This's my problem ( AIX ) switchshow | awk ' { if ( $1==0 ) print $0; }'It works But these below doesn't switchshow | awk ' { if ( $1==0 1 2 3 4 7 9 12 15 ) print $0; }'switchshow | awk ' { if ( $1== 7 9 12 15 ) print $0; }'Somebody help, please :(:(:( (3 Replies)
Discussion started by: bobochacha29
3 Replies

2. Shell Programming and Scripting

awk problem

i have an email list in file.txt with comma separated line1 - FIELD1,pippo@gmail.com,darth@gmail.com line2 - FIELD2,pippo@gmail.com,darth@gmail.com,sampei@gmail.com output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3,$4}' spreadsheet.txt)but awk delete some letters at the... (8 Replies)
Discussion started by: pasaico
8 Replies

3. Shell Programming and Scripting

awk if else problem

Hi, I am trying to put if else on some field of a file but not getting it where to put it. find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\(\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG="$DATE_SYS" -v IN="" ' BEGIN { FS = ";" OFS = ";"... (9 Replies)
Discussion started by: abhi1988sri
9 Replies

4. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

5. Shell Programming and Scripting

Problem with AWK

when i used to run this command A2=`cat temp |awk -F "," '{print $7}' | awk -F ";" '{print $1}'` give the requited O/P but when i use this command in script its taking only is there any problem in using this command in script or spaces are not readable in script (2 Replies)
Discussion started by: sagar_1986
2 Replies

6. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

7. Shell Programming and Scripting

awk problem

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files. i tried with awk $>ls -lh | awk '/^-/ && $5 >= 100k {print $8 $5}' but it is not working pls tell... (3 Replies)
Discussion started by: abhikamune
3 Replies

8. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

9. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

10. Shell Programming and Scripting

awk problem.

Hi, I have a file containing this data. *** *** *** 123 34 345 456 12 478 *** *** *** now i want to create a new file where third coloum is not null. i tried awk but it is not working. my command like this awk $3 != '/***/' | "{print $1 $2 $3... (1 Reply)
Discussion started by: rajan_ka1
1 Replies
Login or Register to Ask a Question