Results 1 to 4 of 4
hi
I am trying to run head or tail command from externa argument as below.
for example test.sh
and run ./test.sh 1000
------------------
#/bin/ksh
print "fred: $*"
print "$0: $1 ...
- 04-25-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 1
ksh head/tail argument variable
hi
I am trying to run head or tail command from externa argument as below.
for example test.sh
and run ./test.sh 1000
------------------
#/bin/ksh
print "fred: $*"
print "$0: $1 and $2"
print "$# arguments"
head -$1 /u01/scripts/dump*|grep sessio|awk '{ print $1`}> /u01/out.txt
-------------------------------------------------
whenever I run it gives an empty out file.
I tried to several times but no result. I alsoedit script as
head -1000 /u01/scripts/dump*|grep sessio|awk '{ print $1`}> /u01/out.txt
to see if there another reason, but in this way I can get positive result.
Regards
Sinano Deregole
- 04-25-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Did you get an error message when you ran the script? When I did I got 'no closing quote'. Looks like your awk command is wrong. It's
head -$1 /u01/scripts/dump*|grep sessio|awk '{ print $1`}> /u01/out.txt
when it should be:
head -$1 /u01/scripts/dump*|grep sessio|awk '{ print $1}'> /u01/out.txt
Also change the first line to:
#!/bin/ksh -vx
The '-vx' will run the script in verify mode, you'll see the commands as they execute. Also note that your first line didn't have an exclamation point after the pound character.
- 04-27-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
Hey there,
The above reply is absolutely correct about the format of the awk command and the pound-bang line. Just one extra thing, if you need to figure out what's wrong in your pipe chain.
If you can, run the series of piped commands using bash and then echo the value of the PIPESTATUS variable. It will tell you which command in your pipe chain is giving the error.
Since you can get a good result when running this a separate way, this might not have anything to do with I/O redirection, but you can always try to tie stderr to stdout at each point in the chain, too
, Mike
- 04-28-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
i see you have a little bit of awk code there in your script. I suggest you just use awk.
Code:#!/bin/ksh number=$1 awk -v n=$number 'NR < n && /session/{ print $1}' /u01/scripts/dump* > /u01/out.txt


Reply With Quote