Problem in running an AWK script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Problem in running an AWK script
# 1  
Old 12-28-2006
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
Rachana
# 2  
Old 12-28-2006
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.
# 3  
Old 01-02-2007
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
Rachana
# 4  
Old 01-03-2007
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.
# 5  
Old 01-03-2007
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,
Rachana
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem running db2 commands in awk

Hi , I am trying to use the below in awk but failed, any one assist please, awk '{ print $0; if ( $0 ~ /LOADTMP1/ ) { print $4; Table_name=system($( db2 -x "SELECT TRIM(TD.BSCHEMA) || '.' || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE TD.BTYPE='T' AND... (2 Replies)
Discussion started by: Nandy
2 Replies

2. Shell Programming and Scripting

Problem running awk script in Debian 6.0.2

Hello to all, May be some expert could help me. I have the below awk script that works correctly in Cygwin: awk -F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N=$5;next} $10 in N && FNR>1 { Y=$8 Z=(N==$8)?"Yes:"No"; } END{ for(k in N) {print k,Y,N,Z?Z:"Not_Found"} }' file2 file1But when I... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

3. Shell Programming and Scripting

Problem on running a script

Hi all, Running follow command on terminal; $ glance -T cloudlive -I ubuntu -K ubuntu123 -N \ http://127.0.0.1:5000/v2.0/OpenX add name="cirros" is_public=true \ container_format=ovf disk_format=raw < \ /srv/cirros-0.3.0-x86_64-disk.img It works without problem. Putting it on a... (5 Replies)
Discussion started by: satimis
5 Replies

4. Shell Programming and Scripting

Problem with running awk script in pbs file

Hi guys I have a problem with one module of my script. It's awk script running in pbs file - It's working when I make a call from pbs to separate awk only file like this but when I try to execute this code in pbs file it fails awk 'BEGIN { max = -1000; min = 1000 } { {$4 == "TCO"} ... (2 Replies)
Discussion started by: grincz
2 Replies

5. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

6. Shell Programming and Scripting

Problem with running the remote script

Hi All, I am running a script which is present on remote machine using ssh command. the remote script is failing when try to load a property file. It says file does not exist. Any idea what should be the problem for this. Thanks Supriya. (7 Replies)
Discussion started by: supriyabv
7 Replies

7. UNIX for Dummies Questions & Answers

problem running script

hey, i'm trying to run several processes due 2 loops : the code is: cd ${TIBCO_HOME}/tra/domain/${DOMAIN}/application/ for app_name in ls * do echo $app_name if && && ; then exit else echo $app_name cd $app_name pwd for ps_name in ls *.sh do echo... (2 Replies)
Discussion started by: ohadr
2 Replies

8. Shell Programming and Scripting

Problem Running Touch From Script

Hi I'm trying to touch a number of files. I thought that it would be time-saving to put all the touch commands into a script and execute the script from the command line. This is what I did (as a test) -- I created a small list of commands and put the commands into a text file I set... (6 Replies)
Discussion started by: Viola
6 Replies

9. Shell Programming and Scripting

Problem in Running Script

Hi friends, i have written one small script named as "size.sh"..... while running its giving syntax error at line no 2: 'str=$' unexpected. How to run this file ??? please help me. file content is : ----------------------------- #!/bin/sh str=$( df -k | grep /usr/local)... (14 Replies)
Discussion started by: samfrance
14 Replies

10. Solaris

Problem running script remotelly.

Hi, i would like a help with this problem. i have the following situation: 4 workstations SUNs: SunOS porsche 5.8 Generic_117350-18 sun4u sparc SUNW,Sun-Blade-100 SunOS jaguar 5.8 Generic_108528-18 sun4u sparc SUNW,Sun-Blade-100 SunOS mercedes 5.8 Generic_117350-18 sun4u sparc... (2 Replies)
Discussion started by: dougpss
2 Replies
Login or Register to Ask a Question