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
how to access values of awk/nawk variables outside the awk/nawk block? saniya Shell Programming and Scripting 5 05-13-2008 08:37 AM
How to use awk instead of nawk? kinmak UNIX for Dummies Questions & Answers 2 05-07-2008 05:34 AM
nawk & awk sd12 UNIX for Advanced & Expert Users 5 05-05-2008 11:46 AM
nawk/ksh help DeltaX Shell Programming and Scripting 0 03-06-2008 03:54 PM
nawk use ctap UNIX for Advanced & Expert Users 2 01-17-2008 06:45 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 02-11-2009
beppler beppler is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 15
nawk help

What am I doing wrong here? I get syntax error.

I am trying to parse a file looking for the lines with "running" as the first field then print the 5th field, then looking at the 9th field for specific values and writing the whole line to a junk file.

nawk ';
{if ($1 == "running") print $1 >> ./junk1;
if ($9 == "S73isid") {print $0} >> ./junk1;
if ($9 == "S750vxpal.gridnode") {print $0} >> ./junk1;
if ($9 == "S75vxpal.StorageAgent") {print $0} >> ./junk1;
if ($9 == "S75vxsmfd") {print $0} >> ./junk1;
if ($9 == "S760vxpal.actionagent") {print $0} >> ./junk1;
print}' rc2.d_listing

Thanks!!
  #2 (permalink)  
Old 02-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
nawk -f bep.awk rc2.d_listing > ./junk1

bep.awk:

Code:
BEGIN {
  n=split("S73isid S750vxpal.gridnode S75vxpal.StorageAgent S75vxsmfd S760vxpal.actionagent", list)
  for(i=1; i<=n; i++) {
    list[list[i]]=i
    delete list[i]
  }
}
$1 == running { print $5; next}
$9 in list


Last edited by vgersh99; 02-11-2009 at 04:02 PM..
  #3 (permalink)  
Old 02-11-2009
beppler beppler is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 15
Ran it got this??

/tmp/wbe]# nawk -f bep.awk rc2.d_listing > ./junk1
nawk: newline in string S73isid S7... at source line 2
context is
n=split("S73isid S750vxpal.gridnode S75vxpal.StorageAgent S75vxsmfd S760vxpal. >>>
<<<
nawk: newline in string , list) S7... at source line 3
nawk: syntax error at source line 4 missing )
  #4 (permalink)  
Old 02-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by beppler View Post
Ran it got this??

/tmp/wbe]# nawk -f bep.awk rc2.d_listing > ./junk1
nawk: newline in string S73isid S7... at source line 2
context is
n=split("S73isid S750vxpal.gridnode S75vxpal.StorageAgent S75vxsmfd S760vxpal. >>>
<<<
nawk: newline in string , list) S7... at source line 3
nawk: syntax error at source line 4 missing )
sorry - copy/paste wrapped newline - edited the original post.
  #5 (permalink)  
Old 02-11-2009
beppler beppler is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 15
OK fixed the syntax error but
what I was hoping for is something like this
IP address (Field 5) then the "S" Files
ie:
196.196.1.10 S*
196.196.1.10 S*
196.196.1.10 S*
196.196.1.10 S*
196.196.1.11 S*
196.196.1.11 S*
196.196.1.11 S*
196.196.1.11 S*
  #6 (permalink)  
Old 02-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by beppler View Post
OK fixed the syntax error but
what I was hoping for is something like this
IP address (Field 5) then the "S" Files
ie:
196.196.1.10 S*
196.196.1.10 S*
196.196.1.10 S*
196.196.1.10 S*
196.196.1.11 S*
196.196.1.11 S*
196.196.1.11 S*
196.196.1.11 S*
Sorry, I have no idea what the "S" files are and I don't have a sample file you're trying to parse...
In your original code you're outputting the ENTIRE line (print $0) if the NINTH field is one of the matched strings.
And I think you wanted to output the 5-th field if the frst field is 'running'.

This is what I coded based on your explanation and a piece of code you've given.

If want you can provide a sample data file, a desired output and a description (once again) of what you're trying to achieve.
Please use vB Codes when posting any data samples.
  #7 (permalink)  
Old 02-11-2009
beppler beppler is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 15
Sorry for the misunderstanding!!

S* Stands for S73isid
S750vxpal.gridnode
S75vxpal.StorageAgent
S75vxsmfd
S760vxpal

if "running" output 5th field then if a match on the 9th field print the whole line is OK

I am getting the whole line and that is fine I just never get the 5th if running is 1st field..

Thanks!!!!
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 11:30 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