[awk] Simple things not working on Solaris 10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [awk] Simple things not working on Solaris 10
# 1  
Old 11-07-2011
[awk] Simple things not working on Solaris 10

Hi,

Don't know if this is Solaris 10 or that the shell on Solaris 10 is working against me.
But this works fine on HP-UX 11i, but not on Solaris 10:

Code:
# cat /tmp/test_file
1:een
2:twee
3:drie
# cat /tmp/test_file | /bin/nawk 'END {print $NF}'

# cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'

#

Also tried to use awk iso nawk.
And tried sh, ksh and bash.

Any ideas why this is not working ?

---------- Post updated at 11:04 AM ---------- Previous update was at 11:03 AM ----------

Here the HP-UX 11i output:

Code:
# cat /tmp/test_file | /bin/nawk 'END {print $NF}'
3:drie
#  cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'
3

# 2  
Old 11-07-2011
Not every awk keeps the value of $0,$1..$NF after the END clause... (This behaviour is unspecified by the standard) Try:
Code:
nawk '{last=$NF} END{print last}' infile


Last edited by Scrutinizer; 11-07-2011 at 06:14 AM..
# 3  
Old 11-07-2011
Try:
Code:
/usr/xpg4/bin/awk '{.....}' file

# 4  
Old 11-07-2011
Code:
nawk '{last=$NF} END{print last}' infile

That is indeed working.

What about the other example ?

Code:
#  cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'

---------- Post updated at 11:17 AM ---------- Previous update was at 11:15 AM ----------

Code:
/usr/xpg4/bin/awk '{.....}' file

Is not working.
Same result.
# 5  
Old 11-07-2011
Try:
Code:
nawk -F: '{last=$1} END{print last}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-07-2011
Quote:
Originally Posted by Scrutinizer
Try:
Code:
nawk -F: '{last=$1} END{print last}' infile

Perfect !
Thanks.

---------- Post updated at 01:18 PM ---------- Previous update was at 11:54 AM ----------

The 'trick' is to save the fields one wants use in the end clause in the beginning.
Example:
Code:
nawk '{f1=$1; f2=$2; f3=$3} END{print f1, f2, f3}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple grep is not working properly on busybox

Hi, I'm trying to write shell scripts on busybox bash on windows and grep is not working for simple regular expression like $ grep FEN * bash: grep: Invalid argument but the same grep works fine if use the single file instead of asterisk $ grep FEN test $ Am I doing something... (5 Replies)
Discussion started by: prvnrk
5 Replies

2. Shell Programming and Scripting

Simple sftp script not working - Please help

I have the below sftp script to transfer a file from a linux host(source) to another linux host(target). Public key is already set up in target host and I am able to transfer file using sftp from source to target. But not sure why the below script(ftp_script) is not working. Any help in this... (3 Replies)
Discussion started by: Armaan
3 Replies

3. UNIX for Dummies Questions & Answers

A simple join, but nothing is working out for me

Guys, I want to join two files. You might have seen this many times. I just don't get the desired output. Searching the forum, No proper links :( Input: File1 test1 test2 test3 File2 is bad is not bad Output Needed: test1 is bad test2 is bad (4 Replies)
Discussion started by: PikK45
4 Replies

4. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

5. Shell Programming and Scripting

A simple variable subst is not working

Hi what i want: listing files in a special range ls -lrt 20120601{05..06}* ... -rw-rw-r-- 1 imp imp 279 1. Jun 07:51 201206010550 -rw-rw-r-- 1 imp imp 279 1. Jun 07:01 201206010600 -rw-rw-r-- 1 imp imp 279 1. Jun 07:11 201206010610 -rw-rw-r-- 1 imp imp 279 1. Jun 07:21... (1 Reply)
Discussion started by: IMPe
1 Replies

6. Shell Programming and Scripting

simple cgi script not working

hi all, i have installed simple cgi-script under apache/cgi-bin directory hello.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print <<END_HTML; <html> <head></head> <body>Hello, World!</body> </html> END_HTML when i hit the url... (6 Replies)
Discussion started by: raghur77
6 Replies

7. Shell Programming and Scripting

Simple BASH script not working?

So I need a script that does the following: If a certain user is logged in Run `command` Else Echo “incorrect user” This is my first stab...which doesn't work: #!/bin/bash X="user=`ls -l /dev/console | cut -d " " -f 4`" Y="foobar" echo $X echo $Y (4 Replies)
Discussion started by: doubleminus
4 Replies

8. Shell Programming and Scripting

simple grep is not working for me

Hi, On the log Netscape log, I need to grep for 500 error. I am doing that but I also get 1500 in that same log. cat access |grep "500" Results: "GET /css/RBR.css HTTP/1.1" 200 15000 304 - - - 399 639 523 164 0 This not what I need... Please advice. (4 Replies)
Discussion started by: samnyc
4 Replies

9. Shell Programming and Scripting

simple perl script not working

why won't below work? I am trying to see a)sipfile has username of the system. b)it will read the sipfile and do a grep function against the /etc/passwd c)it will save that output to /tmp/result.. but my script is just hanging... #!/usr/bin/perl -w open(SIPFILE, "</tmp/sipfile") ... (4 Replies)
Discussion started by: hankooknara
4 Replies

10. Shell Programming and Scripting

Why this simple script, is not working ?

Hi everybody I want to create 20 file using simple script - listed bellow-. But the script doesn't work. I hope anyone guide me to correct this script ---------------- The script integer number=01 until (($number==21)) do >TELE-LOG-$number number=$number+01 echo $number done exit... (4 Replies)
Discussion started by: so_friendly
4 Replies
Login or Register to Ask a Question