awk adjustment to print total


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk adjustment to print total
# 1  
Old 06-08-2014
awk adjustment to print total

im trying to print all lines in the /var/log/syslog file that contain the pattern CRON. and after all the lines have been printed, i want a total of all the lines that contained "CRON" to be printed at the end.

the below command is printing the correct lines, but it is giving me the sum of all lines in the syslog file, instead of only giving a total of lines that contained CRON
Code:
awk "BEGIN{count=0} /CRON/ {print} { count++ }  END { print count }" /var/log/syslog

# 2  
Old 06-08-2014
Correct your code like below :

Code:
awk '/CRON/{print; count++ }END { print count }'  /var/log/syslog

This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adjustment to current awk statement

Hello all, I have a script that currently works very well but I would like to make a change so that I could prompt for user input for a 2 digit numeric field that would represent the month instead of using the system date for the month. This is my current awk script that Don so graciously... (1 Reply)
Discussion started by: ziggy6
1 Replies

2. Shell Programming and Scripting

Search subdirectories and find and print total files

Hi All, I have a folder name lets say path/to/folder/CUSTOMER and under this i have several folders and each of these subfolder have serveral subfolders and so on and at some point i will have a folder name called "FTP_FILES" . I need to search for these folders named "FTP_FILES and then... (10 Replies)
Discussion started by: Kevin Tivoli
10 Replies

3. Shell Programming and Scripting

awk for total

Have a input file like this ..... attachments 100G shared 1T archive 300M documents 300G remotedocs 150M I need the total in GB's ... where as M=MB,G=GB,T=TB Basically need awk to calculate the total based on end... (5 Replies)
Discussion started by: greycells
5 Replies

4. UNIX for Dummies Questions & Answers

Print summary or the total disk usage of conf file

hey i want to print the summary or the total disk usage of the configuration files that are in the /etc directory printed in human-readable format. i think i got somewhere right as am using wc *.conf commands but i am unsure how to use to put it in human-readable format with the wc command. ... (13 Replies)
Discussion started by: stefanere2k9
13 Replies

5. Ubuntu

Brightness adjustment

Hi all, I am using Ubuntu 10.04 LTS in Samsung N148. I can't see any option to adjust brightness in System->Preference->monitor. Is there any shell command to adjust brightness ? I have used xgamma -gamma but it change the gamx not brightness. Cheers (7 Replies)
Discussion started by: gvj
7 Replies

6. Shell Programming and Scripting

Print available running instance out of total

Hello. I have a status command in AIX box, which provides output as below: $ status You are running the application on pegasus2 ----Program Name------|--Avail / Total---------| MQ | 1/2 | ORACLE | 10/10 | TMADMIN ... (3 Replies)
Discussion started by: panchpan
3 Replies

7. Shell Programming and Scripting

How to get total time using awk

Hi guys, I can't find a solution to sum the h:m:s: columns. 28/05/2010 03h 29min 34seg ADSL TELEMAR 28/05/2010 12h 19min 21seg ADSL TELEMAR 29/05/2010 04h 20min 02seg ADSL TELEMAR 29/05/2010 04h 31min 45seg ADSL TELEMAR 30/05/2010 06h 10min 43seg ADSL TELEMAR Thanks Use code... (8 Replies)
Discussion started by: ashimada
8 Replies

8. Shell Programming and Scripting

awk total and print if

hi all! I have a space delimited file... I would like to total column 3 on the condition that column 2 is less than 1030 to a variable in my script something like this: TOTAL="`awk '{$2 < 1030} {s+=$3}END{print s}' file`" Seem to be ignoring the {$2 < 1030}, I'm not sure of the... (3 Replies)
Discussion started by: lyoncc
3 Replies

9. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies
Login or Register to Ask a Question