The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Open google homepage with search results ramkishore Shell Programming and Scripting 1 05-27-2008 07:37 AM
Secure Search Returns Best Results iBot Oracle Updates (RSS) 0 04-06-2008 05:10 AM
Operations on search results nj302 Shell Programming and Scripting 4 01-13-2006 03:15 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-11-2008
hk18 hk18 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 4
AWK - no search results

Hi all,

I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out.

I created an awk file that look like this:

$ cat myawk.awk
BEGIN {
VAR1=PATTERN1
VAR2=PATTERN2
}

/VAR1/ { flag=1 }
/VAR2/ { flag=0 }
{ if (flag == 1) { print $0 } }

The purpose of this awk file is to accept 2 patterns from the command line and extract sections that is between these 2 patterns. And I'm using this file to search for sections that in between [W] and [I], also [E] and [I]. Therefore, in command line, I set

PATTERN1="^\[.\]" and PATTERN2="^\[I\]" :

$ gawk -v PATTERN1="^\[.\]" -v PATTERN2="^\[W\]" -f myawk.awk < myfile.txt

and I'm not getting any output. However, if I change the awk file to the following:


$ cat myawk_no_input.awk
BEGIN {
^\[.\]=PATTERN1
^\[I\]=PATTERN2
}

/^\[.\]/ { flag=1 }
/^\[I\]/ { flag=0 }
{ if (flag == 1) { print $0 } }

I'll get what I needed. Can anyone please explain to me what have I done wrong in the first version of myawk.awk?

Thanks!
 

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 01:01 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