Sponsored Content
Full Discussion: GAWK/GREP Equivalent
Top Forums Shell Programming and Scripting GAWK/GREP Equivalent Post 302720137 by metallica1973 on Tuesday 23rd of October 2012 01:35:51 PM
Old 10-23-2012
GAWK/GREP Equivalent

What is GAWK equivalent to greps -B 5 -A 5?

Code:
zgrep -i "^oct 20" /var/log/syslog*|grep -iB 5 -A 5 'postfix\/pickup
/var/log/syslog.1.gz:Oct 20 01:55:01 elmo CROND[7682]: (mail) CMD (/usr/bin/python -S /usr/lib64/mailman/cron/gate_news)
/var/log/syslog.1.gz:Oct 20 02:00:01 elmo CROND[7701]: (mail) CMD (/usr/bin/python -S /usr/lib64/mailman/cron/gate_news)
/var/log/syslog.1.gz:Oct 20 02:00:02 elmo CROND[7704]: (root) CMD (/home/davider/scripts/backups/saintbk.sh full )
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo kernel:  CIFS VFS: Error 0xfffffffb on cifs_get_inode_info in lookup of \backups\automated
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo last message repeated 11 times
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo postfix/pickup[7339]: 585F8E607F: uid=0 from=<root>
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo postfix/cleanup[7716]: 585F8E607F: message-id=<20121020060003.585F8E607F@elmo.localdomain>
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo postfix/qmgr[3925]: 585F8E607F: from=<root@elmo.localdomain>, size=1723, nrcpt=1 (queue active)
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo postfix/local[7718]: 585F8E607F: to=<postfix@elmo.localdomain>, orig_to=<root>, relay=local, delay=0.32, delays=0.05/0.2/0/0.08, dsn=2.0.0, status=sent (delivered to mailbox)
/var/log/syslog.1.gz:Oct 20 02:00:03 elmo postfix/qmgr[3925]: 585F8E607F: removed
/var/log/syslog.1.gz:Oct 20 02:01:01 elmo CROND[7723]: (root) CMD (nice -n 19 run-parts --report /etc/cron.hourly)
--
/var/log/syslog.1.gz:Oct 20 03:55:01 elmo CROND[8208]: (mail) CMD (/usr/bin/python -S /usr/lib64/mailman/cron/gate_news)
/var/log/syslog.1.gz:Oct 20 04:00:01 elmo CROND[8227]: (mail) CMD (/usr/bin/python -S /usr/lib64/mailman/cron/gate_news)
/var/log/syslog.1.gz:Oct 20 04:00:01 elmo CROND[8230]: (root) CMD (/home/davider/scripts/backups/spacechk.sh)
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo kernel:  CIFS VFS: Error 0xfffffffb on cifs_get_inode_info in lookup of \backups\automated
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo last message repeated 4 times
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo postfix/pickup[8202]: 0D62FE607F: uid=0 from=<root>
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo postfix/cleanup[8235]: 0D62FE607F: message-id=<20121020080002.0D62FE607F@elmo.localdomain>
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo postfix/qmgr[3925]: 0D62FE607F: from=<root@elmo.localdomain>, size=1018, nrcpt=1 (queue active)
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo postfix/local[8237]: 0D62FE607F: to=<postfix@elmo.localdomain>, orig_to=<root>, relay=local, delay=0.09, delays=0.08/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
/var/log/syslog.1.gz:Oct 20 04:00:02 elmo postfix/qmgr[3925]: 0D62FE607F: removed
/var/log/syslog.1.gz:Oct 20 04:01:01 elmo CROND[8243]: (root) CMD (nice -n 19 run-parts --report /etc/cron.hourly)

Once the occurrence is found, I want to see 5 lines before and after. Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies

2. Shell Programming and Scripting

perl equivalent to grep -c

Guess the subject lines says it all. What is the perl equivalent to grep -c -c, --count Suppress normal output; instead print a count of match- ing lines for each input file. With the -v, --invert- match option (see below), count non-matching lines. ... (6 Replies)
Discussion started by: popeye
6 Replies

3. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

4. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. Shell Programming and Scripting

awk (gawk) grep & columns

Hi, I'm working with gawk (on DOS) today. A goal is: find a string for-instance '123', cut a line in two columns and write second one. The problem is: command line works OK, awk file doesn't. But I would like to work with file because there are many strings to find. input: line command: awk... (4 Replies)
Discussion started by: frajer
4 Replies

6. Shell Programming and Scripting

SED equivalent for grep -w -f with pattern having special characters

I'm looking for SED equivalent for grep -w -f. All I want is to search a list of patterns from a file. Also If the pattern doesn't match I do not want "null returned", rather I would prefer some text as place holder say "BLANK LINE" as I intend to process the output file based on line number. ... (1 Reply)
Discussion started by: novice_man
1 Replies

7. Shell Programming and Scripting

grep -v equivalent in perl

I have to do grep -v in a perl script. I want to exclude blank lines and lines having visitor. #grep -v visitor abc.txt |grep '.' file:abc.txt 1340 not booked 16D:D9 tourist 8 1341 not booked 16C:D4 tourist 25 1342 not booked 16D:C4 visitor 7 1343 not booked 01C:D9 visitor 6 1344... (4 Replies)
Discussion started by: dynamax
4 Replies

8. Shell Programming and Scripting

sed Equivalent for awk/grep

Any equivalent command using awk or grep? sed -n "/^$(date --date='10 minutes ago' '+%b %_d %H:%M')/,\$p" /abc.log (7 Replies)
Discussion started by: timmywong
7 Replies

9. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

10. AIX

Need grep -v Equivalent for AIX

Need grep -v "Hello" equivalent for AIX (9 Replies)
Discussion started by: mohtashims
9 Replies
syslog.conf(4)						     Kernel Interfaces Manual						    syslog.conf(4)

NAME
syslog.conf - syslogd configuration file SYNOPSIS
facility.severity destination Where: Is part of the system generating the message, specified in /usr/include/sys/syslog_pri.h. See also the syslogd(8) reference page. The severity level, which can be emerg, alert, crit, err, warning, notice, info, or debug. See /usr/include/sys/syslog_pri.h. The syslogd daemon logs all messages of the specified severity level plus all messages of greater severity. For example, if you specify level err, all messages of levels err, crit, alert, and emerg or panic are logged. A local file pathname to a log file, a host name for remote logging or a list of users. In the latter case the users will receive messages when they are logged in. An asterisk (*) causes a message to be sent to all users who are currently logged in. DESCRIPTION
The /etc/syslog.conf file is a system file that enables you to configure or filter events that are to be logged by syslogd. You can specify more than one facility and its severity level by separating them with semicolons. You can specify more than one facility logs to the same file by separating the facilities with commas, as shown in the EXAMPLES section. The syslogd daemon ignores blank lines and lines that begin with an octothorpe (#). You can specify # as the first character in a line to include comments in the file or to disable an entry. The facility and severity level are separated from the destination by one or more tab characters. If you want the syslogd daemon to use a configuration file other than the default, you must specify the file name with the following com- mand: # syslogd -f config_file Daily Log Files You can specify in the /etc/syslog.conf file that the syslogd daemon create daily log files. To create daily log files, use the following syntax to specify the path name of the message destination: /var/adm/syslog.dated/ { file} The file variable specifies the name of the log file, for example, mail.log or kern.log. If you specify a /var/adm/syslog.dated/file path name destination, each day the syslogd daemon creates a sub-directory under the /var/adm/syslog.dated directory and a log file in the sub-directory, using the following syntax: /var/adm/syslog.dated/ date / file Where: The date variable specifies the day, month, and time that the log file was created. The file variable specifies the name of the log file you previously specified in the /etc/syslog.conf file. The syslogd daemon automatically cre- ates a new date directory every 24 hours and also when you boot the system. The current directory is a link to the latest date directory. To get the latest logs, you only need to reference the /var/adm/syslog.dated/current directory. EXAMPLES
The following is a sample /etc/syslog.conf file: # # syslogd config file # # facilities: kern user mail daemon auth syslog lpr binary # priorities: emerg alert crit err warning notice info debug # kern.debug /var/adm/syslog.dated/kern.log user.debug /var/adm/sys- log.dated/user.log daemon.debug /var/adm/syslog.dated/daemon.log auth.crit;syslog.debug /var/adm/syslog.dated/syslog.log mail,lpr.debug /var/adm/syslog.dated/misc.log msgbuf.err /var/adm/crash.dated/msgbuf.savecore kern.debug /var/adm/messages kern.debug /dev/console *.emerg * FILES
/etc/syslog.conf /etc/syslog.auth - Authorization file for remote logging. /usr/include/sys/syslog_pri.h - Common components of a syslog event log record. RELATED INFORMATION
Commands: /usr/sbin/syslogd(8), /usr/sbin/binlogd(8) System Administration delim off syslog.conf(4)
All times are GMT -4. The time now is 04:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy