If you save the following in a file named tester:
make it executable and invoke it with:
it, produces the output:
If you invoke it with:
./tester 10
it produces the output:
and, if you invoke it with:
it produces the output:
Although this script was written and tested using a Korn shell, it will work with any shell that performs the basic parameter expansions required in the POSIX shell.
Does this help?
PS: As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
Last edited by Don Cragun; 09-02-2016 at 05:22 AM..
Reason: Add PS.
These 2 Users Gave Thanks to Don Cragun For This Post:
Hi ,
I have a piece of code ...wherein I need to assign the following ...
1) A command line argument to a variable
e.g origCount=ARGV
2) A unix command to a variable
e.g result=`wc -l testFile.txt`
in my awk shell script
When I do this :
print "origCount" origCount --> I get the... (0 Replies)
Hello everybody,
I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator:
#!/bin/csh
set shz=2
set zshift=5
set shzp=`bc -l <<END \
scale = 3 \
-1. * $shz + $zshift \
END`
echo $shzp
The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8.
... (2 Replies)
Hi,
I have an awk script which performs simple operations of variable assignments and finally printing the variables in custom form.
BEGIN {FS=OFS="\n"}
{
v1=substr($0,1,15)
v2=substr($0,16,200)
v3=substr($0,216,20)
print v1 "|" v2 "|" v3
}
The input file being processed... (2 Replies)
Hi All
The below is the script, if i supply the script with the argument -f then it will delete the tmp file . We are having 3 unix system out of that two system are processing this file only one system is not processing and the error showin is below the script ..
can you please help me
... (2 Replies)
Hi all,
For no particular reason, I would like to use awk on a file that contains multiple columns, but let's say only columns 1 and 2 have some text values, and the remainder of the line contains text that I would like to treat as one column, considering I have spaces as delimiter for the... (33 Replies)
Hi Gurus,
I hit a hard block in my script.
when using awk command with variable, I got different result.
Please see below:
my test file as below:
$ cat demofile.txt
filename-yyyy-abcd
filename-xxx-week-pass
filename-xxx-week-run
for testing purpose, I put 3 awk command in one script.... (7 Replies)
Greetings Experts,
We are migrating from AIX to RHEL Linux. I have created a script to verify and report the NULLs and SPACEs in the key columns and duplicates on key combination of "|" delimited set of big files. Following is the code that was successfully running in AIX.
awk -F "|" 'BEGIN {... (5 Replies)