Visit Our UNIX and Linux User Community


SFU awk help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFU awk help
# 1  
Old 12-10-2007
SFU awk help

hi guys

i am trying using this awk command which works perfectly on unix
Code:
awk '$1>=dt' dt="2007-12-03" filename

but when i run same command for same file under SFU it does nothing simply prints the file ( just like cat command ) i am not getting why ?
any way i used sed for same ( little complicated way but it works ) can u tell me u can i make it work ?
# 2  
Old 12-10-2007
Try a standard version of the code:
Code:
dt="2007-12-03"
awk -v dat="$dt" '{ if($1>=dat) {print $0} }'  filename

# 3  
Old 12-10-2007
Quote:
Originally Posted by jim mcnamara
Try a standard version of the code:
Code:
dt="2007-12-03"
awk -v dat="$dt" '{ if($1>=dat) {print $0} }'  filename

Could you please elaborate a bit further?
# 4  
Old 12-10-2007
Well, this does seem odd...
Code:
$ awk   '$1>=dt' dt="2007-12-03" data
2007-12-01 too early
2007-12-03 exact match
2007-12-12 afterwards
$
$
$ awk   '$1>=dt {print $0}' dt="2007-12-03" data
2007-12-03 exact match
2007-12-12 afterwards
$
$
$ uname -a
Interix octave 3.5 SP-8.0.1969.1 x86 Intel_x86_Family15_Model2_Stepping7
$

Both of the above commands violate the man page which states that variable assignments must precede the awk program and have a -v. But doing it right has the same effects...
Code:
$ awk -v dt="2007-12-03" '$1 >= dt' data
2007-12-01 too early
2007-12-03 exact match
2007-12-12 afterwards
$ awk   -v dt="2007-12-03" '$1 >= dt { print $0 }' data
2007-12-03 exact match
2007-12-12 afterwards
$

It looks like a bug to me.
# 5  
Old 12-10-2007
Hm, strange ...
All Awk versions I use and know (nawk, GNU Awk, mawk and even the old broken Solaris awk) behave as expected.
AFAIK the variable assignment var=value is part of the syntax
and it's documented in the man pages (I checked the old Solaris Awk and GNU Awk man pages):

Quote:
Any filename of the form
var=value is treated as an assignment, not a filename, and
is executed at the time it would have been opened if it were
a filename. Variables assigned in this manner are not avail-
able inside a BEGIN rule, and are assigned after previously
specified files have been read.

P.S. It's important to note that the old Awk implementations (ex. Solaris /usr[/bin]/awk) don't support the -v assignment! They support the one discussed above.

Last edited by radoulov; 12-10-2007 at 01:29 PM..
# 6  
Old 12-10-2007
This is cheap, but...

Code:
awk '$1>='"$dt"' filename
  or even:
awk "\$1>=\"$dt\"" filename

It requires neither method for passing-in values, but makes the quoting a bit messy.

Previous Thread | Next Thread
Test Your Knowledge in Computers #272
Difficulty: Easy
Alan Turing, while working at Bletchley, occasionally ran the 40 miles to London when he was needed for meetings there.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tell me about PS command with SFU

Hi all, When I execute ps command with SFU (Microsoft Windows Services for UNIX), the result is returned as an empty line. Other commands will return correct results. How can I get the result of ps command correctly? Thank you. (2 Replies)
Discussion started by: tcx731
2 Replies

2. Windows & DOS: Issues & Discussions

Empty folders with SFU

Hi all, i am currently setting my windows XP environment to use with Services for Unix (NFS Client) to mount my unix file system as a network drive. However, though i could mount the unix file directory successful, but the folder is empty (which is not). Why is this so? i have imported my unix... (6 Replies)
Discussion started by: lchunleo
6 Replies

3. HP-UX

SFU and NFS issues

Hi, I support a small lab of older HP UX 9 and 10 boxes. We have some older NT 4.0 machines at each UX box, with a old ZFS Server programs hosting two mounted directories. (Each UX and NT machine is on its own private network via crossover cable). Due to hardware failure/support EOL on NT, I have... (3 Replies)
Discussion started by: the spyder
3 Replies

4. Shell Programming and Scripting

SQL*Plus under SFU

Hi all I have a problem again under Korn Shell with SFU. If I use sqlplus.exe like this : $ sqlplus.exe "/ as sysdba" SQL*Plus: Release 9.2.0.1.0 SQL> select value from v$parameter where name='user_dump_dest'; VALUE -------------------------------------------------------------... (9 Replies)
Discussion started by: madmat
9 Replies

5. UNIX for Advanced & Expert Users

How to use ps command on SFU emulator ?

Hi all How can I use ps command on korn shell emulated by SFU on Windows Server ? All others commands work fine, but this one I don't know :confused: Many thanks ---------- Post updated at 11:28 AM ---------- Previous update was at 10:12 AM ---------- Ok, it works fine in fact, I'm... (0 Replies)
Discussion started by: madmat
0 Replies

6. HP-UX

SFU/NFS question

I am new in UNIX so pardon me if I am asking this question. We are using SFU in Windows to have a Windows folder mounted over UNIX. While we can see the mount, everytime i cd on the mounted folder (e.g. cd CONFIG) I always get Permission denies error. Does anyone know why I cannot go inside the... (11 Replies)
Discussion started by: Jolas
11 Replies

7. Windows & DOS: Issues & Discussions

Wrong Ouput when using printf under SFU

I used printf to print the following under SFU, lrs=`cat lrs` hrs=`cat hrs` tp=`cat tp` printf “\n\n%5sM = $lrs Ohms%5sX = $hrs Ohms%5sT = $tp %%\n\n\n” > file cat file With the above script, I used %% after $tp only as a percentage sign and I get only the following output: % T =... (5 Replies)
Discussion started by: ilak1008
5 Replies

8. Windows & DOS: Issues & Discussions

FTP using SFU

I'm trying to ftp a file from Solaris to Windows XP Pro using SFU and the command that I used is as follows: ftp -n “host” << cmd user “loginname” “password” cd Directory ls filename error bye cmd If the filename does not exist, it shows the following output: Output to local-file:... (2 Replies)
Discussion started by: ilak1008
2 Replies

9. Windows & DOS: Issues & Discussions

Changing Directory Using SFU

Just installed SFU in my PC running under Windows XP Pro. Could someone tell us how to change directory and to its subdirectories either by Korn Shell or C Shell? I tried, cd f:\ or chdir f:\ but it didn't work. (1 Reply)
Discussion started by: ilak1008
1 Replies

10. Post Here to Contact Site Administrators and Moderators

Interix/MS Windows SFU

Hey guys, Any chance of getting a thread under 'Special Interest Topics' for Interix/SFU? This has to be one of the most poorly documented pieces of software floating around and it works great for interoperability of windows systems with the rest of your unix/linux network rather than having to... (3 Replies)
Discussion started by: chek
3 Replies

Featured Tech Videos