0

I am trying to pass $9 into my executed php command using awk. However the $9 never makes it to the command. If I manually establish the value for param1 everything works.

cat file.name | awk -v date="$(date +"%Y-%m-%d %H:%M:%S")" '{
 x="'"`/usr/bin/php-cgi -f /path/hex2bin.php param1=$9`"'"
print "New value: ",$x
}'
2
  • OBJECTIVE: I want to be able to return the value from php file passing in parameter, make it a variable and later use that variable in my AWK for more execution. Commented Dec 14, 2018 at 1:06
  • You don't need the cat file | ibm.com/developerworks/aix/library/au-badunixhabits.html#ten Commented Dec 14, 2018 at 1:43

1 Answer 1

2

1st point:Though I am not php expert, I have seen usually shell commands run under exec command.

2nd point: You need not to use cat with awk. awk could read any Input_file passed to it. eg--> awk '........' Input_file

A try to fix your code: Since you have NOT mentioned why you are printing x variable again in awk program + why date is mentioned in variable but not being used?

What I am doing here is calling php script by passing $9 with escaping $ in it by awk's system command(Without samples I am not able to run this command).

awk -v s1="'" -v s2="\"" -v date="$(date +"%Y-%m-%d %H:%M:%S")" '
{
  system(s1 "/usr/bin/php-cgi -f /path/hex2bin.php param1= " s2 "$9" s1)
}'  Input_file

But 1 things is there using system command in awk you will be able to execute other/shell commands by it, since it is executing commands in another sub shell so you will NOT be able to take its output value into awk variable, experts could correct me if I missed something here.

EDIT: Or try to use while loop itself.

while read line one two three four five six seven eight nine ten
do
   new_variable=$(your_php_command "$nine")
   echo "Use here new_variable...."
done < "Input_file"
Sign up to request clarification or add additional context in comments.

7 Comments

OBJECTIVE: I want to be able to return the value from php file passing in parameter, make it a variable and later use that variable in my AWK for more execution.
Why don't you create shell script and then your php command there then pass that shell variable to awk script or use a while loop to read file by that you need not to get in puzzle to get back variables to awk etc.
I Just want to pass in $9 into the second line. How can I do this using the ` logic?
@user1157800, I believe I had provided that solution to you and I mentioned already that if you use system command it may not be able to return you back values. I don't believe without system we could call it in awk.
@user1157800, try my EDIT command once too? It is only a guidance for you. You could write your php actual script there and could pass variable to it then, let me know?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.