awk syntax for Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk syntax for Solaris
# 1  
Old 10-24-2009
awk syntax for Solaris

Hi,

Pass variable in SUN SOLARIS awk

I have a file call text

server1 10.0.0.2

When i use this awk command in Mac OS and Linux , everything works as expected.

export HOSTNAME=server1
awk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 ; } ' text1

But when i entered the same command on Solaris it came back with syntax error.

Thanks
# 2  
Old 10-24-2009
Hi.

On Solaris use nawk, or /usr/xpg4/bin/awk.

I would personally delete /usr/bin/awk and link it to nawk!! (but maybe that's just me!)
# 3  
Old 10-24-2009
for the OLD awk on Solaris pass the vars the follwing way:
Code:
awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1

# 4  
Old 10-24-2009
Yes, it would have been constructive to say "the OLD awk on Solaris" doesn't support the -v option!

But it's about the only awk that doesn't.
# 5  
Old 10-24-2009
Thank you all.

I am trying to run awk in finish script after jumpstart installation on Solaris 10 X86.
The boot image during jumpstart does not have awk in /usr/xpg4.

And it doesn't work if I use
awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1

Still syntax error

---------- Post updated at 02:19 AM ---------- Previous update was at 02:15 AM ----------

nawk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 } ' text1

works for me

Thanks guys

---------- Post updated at 02:19 AM ---------- Previous update was at 02:19 AM ----------

nawk -v HOSTNAME=$HOSTNAME ' $1 ~ HOSTNAME { print $2 } ' text1

works for me

Thanks guys
# 6  
Old 10-24-2009
Do you have nawk?

What is the syntax error?
# 7  
Old 10-24-2009
syntax error as follow:
Code:
awk: syntax error near line 1
awk: bailing out near line 1

Probably typo error

command as follow:
Code:
awk ' $1 ~ HOSTNAME { print $2 } ' HOSTNAME="${HOSTNAME}" text1


Last edited by RavinderSingh13; 07-12-2019 at 03:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Nice syntax in csh on Solaris 10

Dear Solaris Experts, I would like to set the lowest priority when running a resource intensive program in C shell on Solaris 10 similar to the following syntax that works in Korn shell: $ nice -n 19 programHowever, I got the following error when running the same command in C shell: 9 ... (3 Replies)
Discussion started by: gjackson123
3 Replies

2. Shell Programming and Scripting

Help with the awk syntax

Hello Experts: While writing a script to help one of the posts on here, I end up writing a wrong one. I am very much eager to know how this can be corrected. Aim was to not print specified columns - lets say out of 100 fields, need to print all but 5th, 10th, 15th columns. Someone already... (13 Replies)
Discussion started by: juzz4fun
13 Replies

3. Solaris

Solaris config files syntax

I have recently been told that on a Solaris 10 system # means default settings, and that ## indicates a comment. Therefore, the following setting in the etc/default/login file #RETRIES=5 indicates that the number of failed login attempts allowed is 5. Is this true or false? Should... (5 Replies)
Discussion started by: jclarkaz
5 Replies

4. Shell Programming and Scripting

awk syntax

Hi I have a bash file which will split a big file to many small files. But I got a syntax error.H="$(head -1 CCC.tped)" awk 'print $0 > $1 ".tped"' CCC.tped for f in $(ls *.tped); do echo "$H\n" "$(cat $f)" >$f; done And -bash-4.1$ bash split awk: print $0 > $1".tped" awk: ^ syntax error... (3 Replies)
Discussion started by: zhshqzyc
3 Replies

5. Shell Programming and Scripting

Solaris bash syntax different from Linux?

I have a script that's meant to check the disk usage on a particular volume and delete the oldest logfile if it's over a certain percentage. It runs fine on a Linux machine, but on a Solaris one, I get this error: diskspace_check.sh: syntax error at line 3: `diskspace=$' unexpected I assume... (2 Replies)
Discussion started by: cara_k
2 Replies

6. AIX

Help with syntax using AWK

I have a file which is comma separated and has quotes. I can use this command and awk -F"," '{ if ($4=="01" print $0 }' test.txt But this doesn't fetch me the data.since it has quotes. If the data has no quotes,the above command works fine. In Unix you can skip quote \" but this doesn't work.... (7 Replies)
Discussion started by: ganesnar
7 Replies

7. Solaris

Syntax error ipfilter solaris 10

Hello everyone. I have a problem with ipfilter, you must create a rule to redirect traffic from the external network to internal server on port 443. New Rule: rdr e1000g0 from xx.xx.xx.69/32 port 443 -> 192.168.10.5 port 443 tcp, use ipnat -CF -f /etc/ipnat.conf, and ipf send me from error:... (0 Replies)
Discussion started by: kadavr
0 Replies

8. UNIX for Dummies Questions & Answers

awk syntax

Little bit confusing while using awk :confused::confused: In Sed while pattern search we can use "(double quotes) i mean $a=hello $cat file.txt |sed -n "/$a/p"this thing work fine But if i use it in awk it's not working How could i do the substitution of pattern by a variables and the... (1 Reply)
Discussion started by: posix
1 Replies

9. Shell Programming and Scripting

awk syntax help

I don't get correct output when I run this command line: nmap -sP failedhost.com | grep -i failed | awk -F '{print $6}' I basically want it to return 'failedhost.com' but its just showing the output of the nmap scan. (8 Replies)
Discussion started by: streetfighter2
8 Replies

10. Shell Programming and Scripting

Help with Awk Syntax

I have written many awk commands which go in multiple lines. I have this confusion many times. Some time they work if i dont terminate them with "\" but some time error. Some time in "if" statements between if and else if i dont use ";" it gives error but sometimes it doesnt. The below... (4 Replies)
Discussion started by: pinnacle
4 Replies
Login or Register to Ask a Question