Results 1 to 2 of 2
Hi
I need to use a shell variable inside a gawk expression,
but i don't manage to do it the way i want to.
To be more specific:
Assume data.txt ...
- 03-18-2010 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 18
gawk and shell variables
Hi
I need to use a shell variable inside a gawk expression,
but i don't manage to do it the way i want to.
To be more specific:
Assume data.txt isi now want to create a script file with the linesCode:200 312 122 -53 9 123 44 0
Code:yprocess 312 [some-complex-parameter-list] >> mod.txt yprocess -53 [some-complex-parameter-list] >> mod.txt yprocess 123 [some-complex-parameter-list] >> mod.txt yprocess 0 [some-complex-parameter-list] >> mod.txt
so what i tried is:but this gives meCode:a=$1 b=calculate_complex_parameter_list $a cat $a | gawk '{ print "yprocess " $2 " $b >> mod.txt" }'
when i move the $b outside of the double quotes:Code:yprocess 312 $b >> mod.txt yprocess -53 $b >> mod.txt yprocess 123 $b>> mod.txt yprocess 0 $b >> mod.txt
i getCode:a=$1 b=calculate_complex_parameter_list $a cat $a | gawk '{ print "yprocess " $2 " " $b " >> mod.txt" }'
i.e. $b is replaced by the current line emitted by catCode:yprocess 312 200 312 >> mod.txt yprocess -53 122 -53 >> mod.txt yprocess 123 9 123 >> mod.txt yprocess 0 44 0 >> mod.txt
In reality, my data file has several hundred lines,
and the complex parameter list consists of several hunderd numbers.
Is there any way to achieve this goal (with or without gawk=?
Thank You
jody
- 03-18-2010 #2
try something like below
Or...Code:#! /bin/sh echo -n "enter something->" read mymsg echo $mymsg | awk '{printf("%s\n", $0)}'
Code:#! /bin/sh echo -n "enter something->" read mymsg myval="123456789" myeval="echo $mymsg | awk '{printf(\"%s $myval\\n\", \$0);}'" eval $myevalLast edited by gerard4143; 03-18-2010 at 12:42 PM.
Make mine Arch Linux


Reply With Quote