awk works on Linux but fails on Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk works on Linux but fails on Solaris
# 1  
Old 05-25-2016
awk works on Linux but fails on Solaris

On linux i have the below command working fine.
Code:
awk '/<app-deploy>/{A=1;++i} /<\/app-deploy>/{print >> "found"i".tmp";A=0} A{;print >> "found"i".tmp"}' deploy.xml

But the same is failing on Solaris
Output:
Code:
awk: syntax error near line 1
awk: bailing out near line 1

Code:
uname -a SunOS mymac 5.10 Generic_150400-23 sun4v sparc sun4v

Can anyone help fix the code.
# 2  
Old 05-25-2016
Use nawk on Solaris.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-25-2016
Use nawk instead /usr/bin/awk is there for compatibility with ancient shell scripts.

Solaris has several sets of "commands under the /usr directory:
/usr/ucb, /usr/bin, /usr/xpg4/bin and so on.

You have to be aware of which set of commands you are using in your aliases or in your PATH on Solaris when you port code to there.
# 4  
Old 05-25-2016
As has been stated in hundreds of threads before, when running awk scripts on Solaris/SunOS systems, change awk to /usr/xpg4/bin/awk or nawk. (And, if there are any internationalized EREs, don't use nawk either. But, that isn't a problem in this script.)

But, your code is also depending on something else that is unspecified in the standards: the standards don't specify the precedence of file redirection versus string concatenation. So, to make your script more portable, use:
Code:
awk '/<app-deploy>/{A=1;++i} /<\/app-deploy>/{print >> ("found"i".tmp");A=0} A{print >> ("found"i".tmp")}' deploy.xml

But, you might want to consider simplifying it a little bit to:
Code:
awk '/<app-deploy>/{A=1;++i} A{print >> ("found"i".tmp")} /<\/app-deploy>/{A=0} ' deploy.xml

Then when running it on Solaris systems, change awk to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 05-26-2016
Quote:
Originally Posted by Corona688
Use nawk on Solaris.
NAWK gives me the below error.

Code:
nawk: syntax error at source line 1
 context is
        /<app-deploy>/{A=1;++i} /<\/app-deploy>/{print >> >>>  "found"i <<< ".tmp";A=0} A{;print >> "found"i".tmp"}
nawk: illegal statement at source line 1

# 6  
Old 05-26-2016
Have you looked at post #4 in this thread???
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command works on Linux but fails on Solaris.

Hi, I am looking for a generic find command that works on both Linux and Solaris. I have the below command that works fine on Linux but fails on solaris.find /web/config -type f '(' -name '*.txt' -or -name '*.xml' -name '*.pro' ')' Fails on SunOS mysolaris 5.10 Generic_150400-61 sun4v sparc... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

sed works on Linux but fails on Solaris

Hi, On Linux i get the desired ouput: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: Executing the same command on Solaris: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: I need to get the desired output on Solaris i.e. WEB_USER and... (4 Replies)
Discussion started by: mohtashims
4 Replies

3. Shell Programming and Scripting

Grep works on Linux but fails on Solaris

Hi, On linux i have the below command working fine. grep -o '<name>.*</name>' deploy.tmp | sed 's/\(<name>\|<\/name>\)//g' deploy.tmp But the same is failing on Solaris uname -a SunOS mymac 5.10 Generic_150400-23 sun4v sparc sun4v Can you tell me how can i get it work on Solaris ?... (6 Replies)
Discussion started by: mohtashims
6 Replies

4. Shell Programming and Scripting

awk regex expression works in AIX but not in Linux

I have following expression: echo "Sun 12 Jul BST 2014\nSun 12 Jul 2014\nSun 12 Jul IS 2014" | awk '/(Sun)+( 12)+( Jul )+({3} )?(2014)/{print;}' I ran above code in AIX box and output is as follows Sun 12 Jul BST 2014 Sun 12 Jul 2014 I ran above code in Linux box and output is as... (8 Replies)
Discussion started by: kamlesh_pradhan
8 Replies

5. Shell Programming and Scripting

Script works with Linux not with Solaris

Hi I have the following script which works in Linux shell but gives issues with Sun OS Solaris 5.10, What i am trying to achieve here is we have a list of file names in list.txt file and we parse each file at a time for a particular pattern and copt next 4 lines after we hit the pattern to a... (6 Replies)
Discussion started by: Yugendra
6 Replies

6. Shell Programming and Scripting

awk -F works on Linux, but not on Solaris

Hello, I found this command works on Linux: $ echo `uptime` | awk -F "load average: " '{ print $2 }' 1.60, 1.53, 1.46 but got error on Solaris: $ echo `uptime` | awk -F "load average: " '{ print $2 }' awk: syntax error near line 1 awk: bailing out near line 1 $ which awk... (2 Replies)
Discussion started by: seafan
2 Replies

7. Shell Programming and Scripting

Delete rest of line with sed works on Linux but not on Solaris

Hi all, Our application installation uses "sed" command to delete rest of line. It work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. yourfile.txt hello and world cat and dog hello world in linux: cat yourfile.txt | sed ‘s/\(\+\)... (3 Replies)
Discussion started by: javac2005
3 Replies

8. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (1 Reply)
Discussion started by: Silverhood
1 Replies

9. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (0 Replies)
Discussion started by: Silverhood
0 Replies

10. Shell Programming and Scripting

Appending line with sed works on Linux but not on Solaris

Hi folks, Our application installation uses "sed" command to append string after specific line or after line number. Both cases work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. i.g: Linux: ----- file foo.txt aaa bbb ccc ddd root#... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question