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
Passing the values to the secondary script when it invoked by primary script venu_eie UNIX for Advanced & Expert Users 2 07-03-2008 07:10 AM
Passing the values to the secondary script when it invoked by primary script venu_eie Shell Programming and Scripting 1 07-03-2008 06:16 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 02:50 AM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 03:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-18-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 161
AWK script

I have written an awk script. If i run it from command prompt with awk -f then it working fine. but when run the same statements in a script and named file as a1.awk and tried to run it awk -f a1.awk temp.txt > temp2.txt I doesn't work.

The script is like this
awk -F'|' '
BEGIN{

}

{ if($4=="1"){
print "*********" a[$3]

if( a[$3] < $6 ){
a[$3]=$7;
b[$3]=$2;
}
else if ( a[$3] == $7 ){
if( $9 == 1 ){
b[$3]=$2;
}
}
}
next;

}
END {
for ( x in b ) {
print x "|" b[x]
}
}

' temp1.txt> /var/tmp/temp2.txt

The above things works fine but when I put same thing in a script like
a1.awk
and run the script awk -f a1.awk temp1.txt > temp2.txt
No output is written to output file.
Please help me.
  #2 (permalink)  
Old 11-18-2008
Diabolist Diabolist is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 44
You list the working code, but not the code that's broken makes it a little hard to help.

I'll provide a simplified, working, example... maybe the problem will pop out at you?

My input file (called z.in):

Code:
10,ten
3,three
1,one
From the command line:

Code:
cat z.in |awk '{FS=","; sum += $1} END {print sum}'
13
Putting the awk junk in a script. Contents of z.awk:

Code:
{FS=","; sum += $1} END {print sum}
and the result:

Code:
awk -f z.awk z.in
13
Putting it all in a script. Contents of z.ksh:

Code:
#!/bin/ksh

awk -f z.awk z.in
And running it:

Code:
./z.ksh
13
  #3 (permalink)  
Old 11-18-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Place the code in a script, make it executable and run it as:

Code:
./scriptname
The script should look like:

Code:
#!/bin/sh

awk -F'|' '
BEGIN{... }
}
.
# Your code
.
{ 
' temp1.txt> /var/tmp/temp2.txt
Regards
Sponsored Links
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 04:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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