The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: problem in running an awk script
dnk
Newbie
Rank: 1



UID 119
Digest Posts 0
Credits 0
Posts 31
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 5, 2007 12:01 PM  Profile | P.M. 
problem in running an awk script



problem in running an awk script



hi everyone,

i am required to write an awk script that can be run from any directory.
this script finds subscription rates for each subscriber at an interval of 10 mins. i want that just by copy pasting the whole script in shell prompt and giving the input arguments, script must work. currenty what i am doing is copying the whole script in a file and making the file executable.

for example

if my file name is test.awk then currently i run it as written below

# test.awk arg1 arg2 arg3

when copy pasting the whole script in shell prompt its not reading the arguments properly. ( i tried reading input arguments with the read command, but that also doesnt work)


my script is

if [ $# -ne 3 ]; then
echo "usage: $0 subscriber_name log_file_name_with_path";
else

awk /$1/ $2 | sort -u -k 2.1,2.8 | awk -f':' '{print $1":"$2":"$3":"$7}'
| awk -f' ' '{print $1,$2,$4}' | awk -f'_000' '(nr == 1) {printf ("1-->%s %s\n",$1,$2)}
(nr > 1) {printf ("0-->%s %s\n1-->%s %s\n",$1,$2,$1,$2)}' | awk 'ors="@" {print}' | awk -f"1-->" '{ for (i = 1; i<=nf;i++) print $i}' | awk -f"0-->" '/0-->/{print $1,$2}' | awk -f'@' '{print $1,$2}' | awk '{if (substr($6,4,2) == substr($2,4,2)) prinrt (""); else {{print $1,$2,"-->",$5,$6,"-->",(($8-$4)*60)/( 1000* (( substr($6,1,2)-substr($2,1,2) ) * 60 + ( substr($6,4,2)-substr($2,4,2) )) ),"k /hr",

( substr($6,4,2)),substr($2,4,2) , substr($6,1,2),substr($2,1,2)}}}'

fi

can anyone suggest how should i read the arguments and run the above script from the shell prompt.
any help will be sincerely appreciated.

thanks in advance


Top
ishan
Newbie
Rank: 1



UID 189
Digest Posts 0
Credits 0
Posts 72
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 5, 2007 12:01 PM  Profile | P.M. 
some info



could you also post what you are trying to achieve and some sample input data and the output you require.

to make sure that the script can be run from any directory, make sure that the directory where the script is located is added to the path variable. once the path variable contains the location of the script's directory, the script can be called from any directory; provided it has a unique name.
Top
Manju99
Newbie
Rank: 1



UID 247
Digest Posts 0
Credits 0
Posts 28
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 5, 2007 12:01 PM  Profile | P.M. 
problem in running an awk script.



thanks for replying. i addred the directory where the script is located in the path variable. it works abosulutely fine.

but i have one more doubt...
out of the 3 inputs which we give while executing this script, one input is a data file. our requirement is, we should be able to give this as input file no matter where the file is located.

is it possible to address this requirement as well?

please help ...

thanks in advance
Top
kodut
Newbie
Rank: 1



UID 226
Digest Posts 0
Credits 0
Posts 33
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 5, 2007 12:01 PM  Profile | P.M. 
full path name



if you give the complete path with the filename, it should work fine. what i am saying is -

code:
script.sh /path/where/file/is/located/filename
if the filename is passed like this, then there shouldn't be a problem.
Top
manoj.rana
Newbie
Rank: 1



UID 10
Digest Posts 0
Credits 0
Posts 21
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 5, 2007 12:01 PM  Profile | P.M. 
thanks a lot...

it clicked to me as soon as i posted the doubt. script is working fine now.

thanks a lot for your help and wish you a very happy and prosperous new year!!

regards,
Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:34 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.006604 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP