Results 1 to 10 of 12
I need to migrate some scripts running on SunOS to Linux,
script running on SunOs used to get the filename that was passed as a paramenter to the .awk script ...
- 12-14-2007 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 11
How to get the Filename in .awk running on Linux
I need to migrate some scripts running on SunOS to Linux,
script running on SunOs used to get the filename that was passed as a paramenter to the .awk script as
outFile=substr(FILENAME,1,3)
the problem is variable FILENAME does not work on Linux, is ther any other alternative?
thanks in advance for the help.
- 12-14-2007 #2
$1 is first parameter passed to a shell script
- 12-14-2007 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 11
its an awk script not shell, the command is
awk -f compareSum.awk prod.dat test.dat
and I need to get prod.dat into some variable.
- 12-14-2007 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
It works for me in this situation:
Producing:Code:#!/usr/bin/env sh # @(#) a1 Demonstrate variable FILENAME in (g)awk. set -o nounset echo ## Use local command version for the commands in this demonstration. echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version bash awk echo # Use nawk or /usr/xpg4/bin/awk on Solaris. echo " Hello, world." > t1 awk ' { print print " Currently reading FILENAME", FILENAME } ' t1 exit 0
The man page may be of value ... cheers, drlCode:% ./a1 (Versions displayed with local utility "version") GNU bash 2.05b.0 GNU Awk 3.1.4 Hello, world. Currently reading FILENAME t1
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-14-2007 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 11
is this working on Linux?, variable FILENAME is working for me on SunOS but not Linux.
- 12-14-2007 #6Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
Well, here is one example how to do it in your compareSum.awk:
As you can see, FILENAME works just fineCode:#!/usr/bin/awk -f BEGIN {} { print FILENAME; }
- 12-14-2007 #7Just Joined!
- Join Date
- Dec 2007
- Posts
- 11
doesn't work on Linux, works on Solaris.
- 12-14-2007 #8Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
And I thought I was running Linux on all my machines...
Execute this on your computer and post here the result:
What Linux distribution do you use?Code:uname -a awk --version | head -1
- 12-14-2007 #9Just Joined!
- Join Date
- Dec 2007
- Posts
- 11
uname -aLinux enycxapramaps017 2.6.9-22.0.2.ELsmp #1 SMP Thu Jan 5 17:11:56 EST 2006 x86_64 x86_64 x86_64 GNU/Linux
awk --version | head -1
GNU Awk 3.1.3
- 12-14-2007 #10Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
It has to work on your system. Try this one (although it's not preferable):
Code:#!/usr/bin/awk -f BEGIN {} { print ARGV[1]; }


Reply With Quote