Wednesday Jan 21, 2009

(n)awk: print matching lines and some more

I think some of you will find the following (n)awk one-liner useful. I am using it from time to time and thought I should document it so that I do not have to think about where to place the "a++" part, for example.

It will print out lines of a file that match a certain pattern, plus some more lines that follow. In this example, I am searching for lines that contain the string "usb" in /var/adm/messages, and print that line plus 4 more (for more lines, decrement the number in the first curly brackets accordingly). A line number will also be printed out for each line:

$ nawk '/usb/{a=-5}{if (a<0){print NR, $0};a++}' /var/adm/messages

Tuesday Jan 15, 2008

Creating (and deleting) a lot of zones

A sample session of the zone-clone and delete-cloned-zones scripts:[Read More]

How to create a lot of zones (and delete them afterwards)

Click here to see the full text:[Read More]

Wednesday Jan 09, 2008

Prepend command output lines with date/time stamps

Click here for details:[Read More]

Friday Jan 04, 2008

Netmask calculation with (n)awk

Click here to see the full text:[Read More]

Wednesday Sep 06, 2006

log file monitoring using tail -f, (n)awk, mailx and xmessage

Short Howto about a powerful but simple notification system for new log entries[Read More]
About

blogfinger

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today