Re: OT: help with mawk
On Thu, Mar 18, 2004 at 06:19:43PM +0100, Joachim Fahnenmueller wrote:
> Hi ghcbc,
>
> VARIABLENAME=$(mawk 'whatever') .
Hi,
Thanks. I can get this to work on the command line, but not in a bash
script.
bash$ Myvar=$(mawk 'gsub("/","") { print }')
The shell will then wait for input. I type some/reasonable/path/name,
then hit carriage return and finally a ctrl-d. Then "echo $Myvar" will
return "somereasonablepathname"
If I make a function _foobar as follows and call it with "_foobar
some/reasonable/path/name" from within the script
function _foobar () {
local symbolicname=""
echo -e "\nBefore statement \$symbolicname = $symbolicname"
symbolicname=$(mawk 'gsub("/","",$1) { print }')
echo -e "\nAfter statement \$symbolicname = $symbolicname"
}
I get as output
Before statement $symbolicname =
After statement $symbolicname =
:(
Do you know what I might do to get this going in the script?
Thanks,
Gerald
>
> BTW: Your syntax seems strange to me. AFAIK it should be something like
> mawk '/pattern/ {action}'
> (see man mawk).
Got what I have straight from man mawk (tempered slightly by "Unix power
tools") :)
/pattern/ = gsub("/","",$1)
{action} = {print}
gsub(a,b,c), global substitution, will replace all instances of a with b in
the input record c, or stdin if c is omitted.
Reply to: