awk command error in Solaris


 
Thread Tools Search this Thread
Operating Systems Solaris awk command error in Solaris
# 1  
Old 05-01-2017
awk command error in Solaris

I have the following code that works perfectly in Cygwin
Code:
$ awk -F, '
 BEGIN   {months ["JAN"]="AP01"; months ["FEB"]="AP02"; months ["MAR"]="AP03";
          months ["APR"]="AP04"; months ["MAY"]="AP05"; months ["JUN"]="AP06";
          months ["JUL"]="AP07"; months ["AUG"]="AP08"; months ["SEP"]="AP09";
          months ["OCT"]="AP10"; months ["NOV"]="AP11"; months ["DEC"]="AP12";
         }
         {TMP = FILENAME
          sub (/\..*$/, "", TMP)
          print> "a_" TMP "_ACTUAL_"months[substr($3,0,3)]"-20" substr($3,5,2)"_RR.txt"
         }
 ' *.txt

This codes splits any txt file into multiple txt files based on field number three. The new files are named using a portion of the original file and the Accounting Periods (AP) listed at the beginning of the script.
As I move the script to the server (Solaris) it generates a syntax error during execution. The error reads: Syntax error near line 7. Line 7 is the assignment of the current filename to the TMP variable.

As I mentioned this is not an issue in Cygwin. The script runs as expected but not so in Solaris. Any help will be greatly appreciated
# 2  
Old 05-01-2017
Where is the END rule?
Or is this just part of the code?
# 3  
Old 05-01-2017
? The END section is optional.
Put the computed target for print in brackets
Code:
print> ("a_" TMP "_ACTUAL_"months[substr($3,0,3)]"-20" substr($3,5,2)"_RR.txt")

And use nawk or /usr/xpg4/bin/awk
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 05-01-2017
Thanks you guys the answer was as simple as changing the awk to gawk.

Problem solved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with awk command between Linux and Solaris

Hi, Here is the output using bash profile on Linux uptime 04:59:14 up 16 days, 4:48, 2 users, load average: 1.00, 1.00, 1.20 Here is the output using bash profile on Solaris uptime 4:00am up 84 day(s), 22:21, 3 users, load average: 0.09, 0.10, 0.12 Now,... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Spot error with my awk command

can any one identify why this command keeps resulting in 1, even though the string i'm searching for actually does not exist in the log? awk 'BEGIN{count++} NR>220 && NR<=223 && /error/ && !/No.*such.*file.*or.*direfctory/ { count++ } END { print count }' /var/log/mail.log i expected it to... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

4. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

5. Shell Programming and Scripting

Getting syntax error while running awk command

Hello Gurus, I am firing the below command : df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}' But I am getting the below error:- ====== syntax error The source line is 1. The error context is {if ($4 > >>> 90%) <<< awk: The... (9 Replies)
Discussion started by: pokhraj_d
9 Replies

6. Solaris

Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t. count=0 while ; do sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR... (4 Replies)
Discussion started by: millan
4 Replies

7. Shell Programming and Scripting

awk script Error in Sun Solaris

Hi Friends, the below script has been through the errors in sun solaris. awk '/%s/{f=0 ;n++; print >(file="OUT_" n); close("OUT_" n-1)} f{ print > file}; /%s/{f=1}' $BASE_DIR/concat.TXT awk: syntax error near line 1 awk: bailing out near line 1 And ls $MERGE_DIR/*.R | awk ' { ... (2 Replies)
Discussion started by: krbala1985
2 Replies

8. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

9. Shell Programming and Scripting

error in awk command

ls filename*.txt | awk -F".Y" '$2 < $v_RUN_DT && $2 > $v_LOAD_DT'|awk ' NR==1' I am getting this error . Can somebody plz point me where is the problem. awk: 0602-562 Field $() is not correct. The input line number is 1. The source line number is 1. (16 Replies)
Discussion started by: RubinPat
16 Replies

10. UNIX for Dummies Questions & Answers

Solaris 9: make: Fatal error:Command failed for target

Hi everyone first of all you should know that I've been working with solaris for a few days only. :) I need to install some programs and I have had the following troubles: 1. When I used /.configure it showed the following message: "no acceptable C compiler found in $PATH" I included... (2 Replies)
Discussion started by: eldiego
2 Replies
Login or Register to Ask a Question