The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 11:14 PM
how could i make a program mixed with many "|", "<" and ">" strugglingman High Level Programming 2 04-29-2006 09:11 AM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2006
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
Question "next" and "gsub" in awk

Yesteray I post a topic talking about log processing, thanks aigles for giving me the script, the first time I heard "next" and "gsub" function, so I decided to do some test work, but I failed, and don't know why

The logfile as follow, notice line 2 contains an username

*snip*
Nov 9 10:12:01 testfirewall root: [ID 702911 local5.info] 0:00:11 accept testfw01-hme0 >hme0 proto: icmp;
src: test001.example.net; dst: abc.dst.net; rule: 1; icmp-type: 8; icmp-code: 0; product: VPN-1 & Fire

Nov 9 10:12:54 testfirewall root: [ID 702911 local5.info] 0:23:54 accept testfw01-hme0 >hme0 proto: tcp; src: maa.example.net; dst: NYCMNYZRHN0.dst.net; service: cerent_1080; s_port: 1649; rule: 30; user: abc; len: 44; srcname: abc.example.net; product: VPN-1 & FireWall-1
*snip*

the request

"find16 column doesn't contain 192.1 or 192.2 or deve"

AND

"there is "user" keyword appears in the log"

AND

delete all the ";" character in the log

my though was like this

gawk 'BEGIN {OFS = "\t"} $16!~"192.(1|2)|deve" && $0~"user" {next} gsub(/;/,"") {print $0}' fw.log

But the script work incorrectly, and I noticed when I just use the first part of the awk program,

gawk 'BEGIN {OFS = "\t"} $16!~"192.(1|2)|deve" && $0~"user"' fw.log

there was no problem, every line match the criterion I defined, but when I add

" {next} gsub(/;/,"") " seemed awk process the logfile totally different, the output result even did not contain "user", I tried to delete "next", still same.

I tried comp.awk.faq, but no information related to "next" function.

So please give me some direction what's wrong with my script? and what exactly "next" do in awk. Thank you!
  #2 (permalink)  
Old 11-15-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
A next statement causes the next input record to be read and pattern testing to restart with the first pattern {action} pair in the program.

The next statement in your awk program excludes all the lines thet you want to select.


Code:
awk '
       # Initialisation : set Output Field Separator to tabulation.
       BEGIN {
          OFS = "\t";  
       }
       # Select lines not containing "user" with field16 not  
       # containing 192.1 or 192.2 or "deve"
       $16!~/192.(1|2)|deve/ && $0~/user/ {
          gsub(/;/, "");     # Deletes all ";" in the current record
          print $0;          # Print current record
       }
    ' fw.log

Jean-Pierre.
  #3 (permalink)  
Old 11-15-2006
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
Quote:
Originally Posted by aigles
A next statement causes the next input record
when you say 'next input record', do that mean next input line?

Quote:
pattern testing to restart with the first pattern {action} pair in the program
I am sorry, I do not get you on this, could you give me a simple example?

Pardon me if this is a stupid question.

Last edited by fedora; 11-15-2006 at 03:42 PM..
  #4 (permalink)  
Old 11-15-2006
ask.jackal ask.jackal is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 24
Yes in the normal case. If you have not modified the variable RS in your awk program, its default value is new line and hence a new record would mean "next line"

John Arackal
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0