Issues running an awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues running an awk script
# 1  
Old 05-09-2012
Issues running an awk script

Hi,

I have an awk script(test.awk) as below which I am trying to execute through the following command and I am getting error as follows. Request your valid inputs on where I am going wrong. Thanks.

:/usr/chandra
Code:
# awk -f test.awk input.txt

 syntax error The source line is 1.
 The error context is
 <<<             >>> BEGIN{
 awk: The statement cannot be correctly parsed.
 The source line is 1.
 syntax error The source line is 2.



test.awk:

Code:
BEGIN{requestID=100;
ORS="";}
{
        requestID=requestID+1;
        print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RequestControl><requestID>"requestID"</requestID></RequestControl>";
        print "<TCRMTx><AgreementName>"substr($0,36)"</AgreementName><ValueString>"$2"</ValueString>";
        print "<AdminPartyId>"$1"</AdminPartyId>\n";
}END{
}

input.txt:

Code:
O0002SJ7GF                1000001. 		GOLDAK INC.


Last edited by Scrutinizer; 05-11-2012 at 03:20 AM.. Reason: code tags
# 2  
Old 05-09-2012
Good news! This is what I get when I do EXACTLY as you say you do:
Code:
<?xml version="1.0" encoding="UTF-8"?><RequestControl><requestID>101</requestID></RequestControl><TCRMTx><AgreementName></AgreementName><ValueString>1000001.</ValueString><AdminPartyId>O0002SJ7GF</AdminPartyId>

Is this what you want? I am using LinuxMint the latest with Cinnamon, no ice...
# 3  
Old 05-09-2012
Yes Exactly this is the output I need. But Why Am i not able to get the success response? I am trying to execute this in an AIX server that has awk installed. Unix is the OS.

Last edited by adept; 05-09-2012 at 09:42 PM.. Reason: corrected OS info
# 4  
Old 05-09-2012
I have no experience with AIX, but it seems you have a very ancient awk that doesn't understand BEGIN. do you have gawk or nawk binary installed as well maybe?
# 5  
Old 05-09-2012
Quote:
Originally Posted by neutronscott
I have no experience with AIX, but it seems you have a very ancient awk that doesn't understand BEGIN.
I find that difficult to believe since the first version of awk supported BEGIN and END (they had very specific requirements on placement with regard to other rules, but they were supported).

It's hard to say, because the original post didn't include code tags, but it looks like there is no space between the BEGIN and the opening curly brace. While I wouldn't expect that to cause an issue, that's the only thing that seems like it might be trouble. Try adding a space:

Code:
BEGIN { requestID=100;
    ORS="";
}
{
    requestID=requestID+1;
    print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RequestControl><requestID>"requestID"</requestID></RequestControl>";
    print "<TCRMTx><AgreementName>"substr($0,36)"</AgreementName><ValueString>"$2"</ValueString>";
    print "<AdminPartyId>"$1"</AdminPartyId>\n";
 }



There is also no need for the end block if it's empty.
# 6  
Old 05-09-2012
I modified the code as above and this time also , I almost got the same error,

mdmdev:/usr/chandra#
Code:
awk -f test.awk input.txt > output.txt
 syntax error The source line is 1.
 The error context is
 <<<            BEGIN { >>>  requestID=100;
 awk: The statement cannot be correctly parsed.
 The source line is 1.
 syntax error The source line is 2.

I am not able to think beyond this. Smilie
Should I try to install gawk or nawk for windows and execute this from there? Can you suggest some URL that contains instructions to download and execute awk,gawk or nawk easily? Thanks.

Last edited by Scrutinizer; 05-11-2012 at 03:20 AM..
# 7  
Old 05-09-2012
No ideas, and I don't have an AIX box to play with. Just because I'm wondering, what happens if you run this:

Code:
awk 'BEGIN { print "hello world" }'

This User Gave Thanks to agama For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem running awk script in Debian 6.0.2

Hello to all, May be some expert could help me. I have the below awk script that works correctly in Cygwin: awk -F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N=$5;next} $10 in N && FNR>1 { Y=$8 Z=(N==$8)?"Yes:"No"; } END{ for(k in N) {print k,Y,N,Z?Z:"Not_Found"} }' file2 file1But when I... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

2. UNIX for Dummies Questions & Answers

Facing issues while running a cronjob !

Hi, I am trying to run a cronjob. But while doing so I am getting the following error message :- can't open yourfile in /var/spool/cron/crontabs directory. No such file or directory How can I resolve this issue ? Please help. Thanks Please view this code tag video for... (14 Replies)
Discussion started by: acidburn_007
14 Replies

3. UNIX for Dummies Questions & Answers

awk: issues for writing a script

%%%%% (7 Replies)
Discussion started by: lucasvs
7 Replies

4. Shell Programming and Scripting

Problem with running awk script in pbs file

Hi guys I have a problem with one module of my script. It's awk script running in pbs file - It's working when I make a call from pbs to separate awk only file like this but when I try to execute this code in pbs file it fails awk 'BEGIN { max = -1000; min = 1000 } { {$4 == "TCO"} ... (2 Replies)
Discussion started by: grincz
2 Replies

5. Shell Programming and Scripting

AWK - Issues with script running at start of month.

I have a script that runs on an AIX 5.3.10.0. It runs perfectly on days that are double digit numbers, but from the 1st to the 9th of the month it runs but does not report anything. The command in the script is as follows: awk -v d=$(date '+%b%d') '/user:warn/ && /has shutdown/ && ($1$2 ==... (2 Replies)
Discussion started by: jimbojames
2 Replies

6. UNIX for Dummies Questions & Answers

swap issues, system is running at 99%

Hi All, I am trying to understand why my system is running at very high. This system is almost out of memory. See below. swapon -s Filename Type Size Used Priority /dev/mapper/VolGroup00-LogVol02 partition 8388600 8235088 -1... (2 Replies)
Discussion started by: samnyc
2 Replies

7. Red Hat

postgresql issues - system running really slow

Hi All, I'm new here. i was wondering if anyone could shed a light on the problem i am having. I use a system for distributing broadband amongst users of for example a hotel, the system was designed by someone in the US and it is based on redhat 2.4 (i know its old) and the system uses... (3 Replies)
Discussion started by: clive306
3 Replies

8. Shell Programming and Scripting

Issues with exit after running jobs in background

I have the following sample script to run a script the jobs with the same priority(in this case field3) in parallel; wait for the jobs to finish and run the next set of jobs in parallel.When all the lines are read exit the script. I have the following script which is doing evrything I want... (1 Reply)
Discussion started by: hyennah
1 Replies

9. UNIX for Advanced & Expert Users

Problem in running an AWK script

Hi Everyone, I am required to write an AWK script that can be run from any directory. This script finds subscription rates for each subscriber at an interval of 10 mins. I want that just by copy pasting the whole script in shell prompt and giving the input arguments, script must work. Currenty... (4 Replies)
Discussion started by: rachana8p
4 Replies

10. Shell Programming and Scripting

is running this command via ssh possible? (formatting issues)

Here is the command I want to run: for pkg in `pkginfo | grep -i VRTS | awk '{print $2}'`; do showrev -p | grep $pkg; done | awk '{print $2 "\t" $7}' | uniq It returns the package info in a form such as: 113210-03 VRTSfspro 112392-06 VRTSvmman 113596-03 VRTSvmpro... (1 Reply)
Discussion started by: LordJezo
1 Replies
Login or Register to Ask a Question