Calling shell script within awk script throws error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling shell script within awk script throws error
# 1  
Old 05-01-2013
Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks


sh: -c: line 0: syntax error near unexpected token `newline'
sh: -c: line 0: `./billdatecalc.sh <SetList>50/10000////D4B790E1////3/0</SetList>'

The "param" variable carries the following data "<SetList>50/10000////D4B790E1////3/0</SetList>"

Code:
awk '
                
                /SetList/ {
                                param = $0
                                cmd = "./billdatecalc.sh "$param""
                                system(cmd)
                }
' touch.xml

# 2  
Old 05-01-2013
too many qoutes:
Code:
cmd = "./billdatecalc.sh \"$param\""

# 3  
Old 05-01-2013
Thanks for the input. The syntax issue is solved. However I don't see any data being passed in the parameter and it always seems to be empty. Any idea ?
# 4  
Old 05-01-2013
The system function if just for execution and only provides the return code, otherwise try using the "cmd" | getline construct instead...
# 5  
Old 05-01-2013
Also awk variables are not referenced with a dollar sign $

Try this:
Code:
param = $0
cmd = "./billdatecalc.sh " param
cmd | getline var
close (cmd)
print var

# 6  
Old 05-01-2013
Using this part of the code again leads to syntax error
sh: -c: line 0: syntax error near unexpected token `newline'


Code:
cmd = "./billdatecalc.sh " param


I tried this one , the syntax issue disappeared however no data being passed in variable "param".

param="<SetList>5/315/3///////NONE/0</SetList>"

Code:
cmd = "./billdatecalc.sh \"$param\""

I tried directly substituting the data directly as follows and the shell script is able to read the data being passed.

Code:
cmd = "./billdatecalc.sh \"<SetList>5/315/3///////NONE/0</SetList>\""


It appears that there is something wrong the way the variable being passed in the shell script

Any idea ? Thanks
# 7  
Old 05-01-2013
Try
Code:
cmd="./billdatecalc.sh " param

You may want to avoid using a relative path name...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script file check throws [: too many arguments

While I am trying to check the filename/s in IF statement of a shell script (RedHat Linux 6) I am getting below error: File check: filename_time2=`date --date='yesterday' +%Y-%m-%d` cd /location/of/the/files/to/copy if then cp server.log-$filename_time2* ../archive/new... (5 Replies)
Discussion started by: Dip
5 Replies

2. UNIX for Dummies Questions & Answers

Calling Shell script Error

Hi All, I need to call a script in another server(Say B).So I logged in my local Machine(say A)using putty and given these command ssh root@hostname cd home\oracle sh script.sh. This is working perfectly.But when I have those command in a shell script and placed in my local... (2 Replies)
Discussion started by: Nivas
2 Replies

3. Shell Programming and Scripting

awk script throws invalid char expression

Hello there, I am new to the awk scripting and getting the following error while running the script. Please can you advise me how to resolve this . Thanks ./sub_del_awk_lat.sh awk: cmd. line:5: warning: escape sequence `\/' treated as plain `/' awk: cmd. line:5: sed -n... (6 Replies)
Discussion started by: Sudhakar333
6 Replies

4. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

5. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

7. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

8. Shell Programming and Scripting

Error when calling sybase stored proc from shell script

Hi, I am writing a script that needs to call a stored proc which would update a column in a table based on a condition. I need to also capture the number of rows updated. However, When I execute the script I keep getting this error: ./test_isql.sh: syntax error at line 33: `end of file'... (3 Replies)
Discussion started by: karthikk
3 Replies

9. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

10. Shell Programming and Scripting

calling dos2unix on shell script from within the script

I have a build script. It was created on Linux. For some reason, I got it to windows and modified it. And brought it back again to Linux. Since there is the question of the ^M chars appearing, the way out is to do a dos2unix on the script file. This is done manually. Is there a way to call... (4 Replies)
Discussion started by: vino
4 Replies
Login or Register to Ask a Question

Featured Tech Videos