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
UNIX for beginners jmy113437 UNIX Desktop for Dummies Questions & Answers 14 05-26-2008 11:55 AM
recommended books for beginners briant UNIX for Dummies Questions & Answers 2 09-17-2007 09:57 PM
'Best' AIX book for beginners ? vilius AIX 1 08-25-2007 02:05 AM
unix course for beginners moose UNIX Desktop for Dummies Questions & Answers 1 04-15-2002 05:50 PM
X-programming for beginners jfsuminist High Level Programming 1 08-19-2001 10:38 PM

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 08-30-2006
Amruta Pitkar Amruta Pitkar is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 54
awk - Beginners Question

I have my inputfile in the following format :

From:sdhfhg
dsfhsdjfjdsfh
dsfjdjshjsd
djfhsdjfjsdhjds
Error Description
<aa.aa.aa.aa.aa.aa>
From:ksljfsdhfjh
djfdsjkf
sdjwoquk
dsfsdfj
Error Description
<dd.dd.dd.dd.dd>

I want to read the lines from tag 'From:' thrul <aa.aa.aa.aa.aa.aa> similarly for the next block. Next I want to read the Error Description and assign an codenumber to it.

I am using the following code :

Code:
#this is my first awk program
BEGIN {errorcode=0}

/From/ {take actions}
      #Read until next 'From'
       {while!(^/<[a-z]/)
         if (/ErrorDesc1/) print "01"
         else if(/ErrorDesc2/) print "02"
         else if(/ErrorDesc3l/) print "03"}

       {if(errorcode != 01 && errorcode != 02 && errorcode != 03) print "04"}
I get the following error :
The error context is
>>> {while! <<< (^/<[a-z])
awk: The statement cannot be correctly parsed.
The source line is 13.

Can someone guide...I am new to awk programming.
  #2 (permalink)  
Old 08-30-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Something to start with:
Code:
BEGIN {errorcode=0}

/From/
      #Read until next 'From'
       {
       while( /^<[a-z]+/ !~ $0 )
         {
         if (match ($0,/Error Description/))
            print "01"
         else if (match ($0,/ErrorDesc2/))
            print "02"
         else if(match ($0,/ErrorDesc31/))
            print "03"
         next
         }
       }

       END{
       if(errorcode != 01 && errorcode != 02 && errorcode != 03) print "04"
       }
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 08:30 PM.


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