[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks Re: OT: help with mawk



On Sat, Mar 20, 2004 at 02:14:25AM +0000, Clive Standbridge wrote:
> On Thu 18 Mar 2004 16:53:58 +0000(-0800), gcrimp@vcn.bc.ca wrote:
> > 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.
> 
> I think the original question was how to strip / characters from a 
> variable in a shell script. Assuming it's a bash script you can do it 
> like this:
> 
> 	that=some/reasonable/path/name
> 	this=${that//\//}
> 
[snip]

> 
> 1. You didn't give mawk any input.
> 
> 2. The third argument to gsub is the name of an awk variable to modify.
>    In this case it's $1 which is the first field of the input line (which
>    is empty because there's no input).

In the code, I called the function with the argument
"some/reasonable/file/name".  I just didn't include the function call in the
code sample I provided.  I have to admit, it wasn't very clearly stated.

Both your solutions (above and below) worked for me.  I'm going to go with
the simple substitution above.  I only attempted the mawk thing because I
didn't know that the /thisbecomes/that/ syntax was available in bash.  But I
am also very glad to know why $1 was not getting through to mawk in the
function, and thus why Joachim's suggestion worked for me on the command
line but not in the script.

Thanks to both Clive and Joachim.

Ta,

Gerald

> 
> 3. I suspect you meant $1 to be the first argument to function _foobar,
>    but it's not because the shell doesn't expand $ inside '', you need
>    to use "" instead.
> 
> Try this:
> 	symbolicname=$(echo "$1" | mawk 'gsub("/","") { print }')
> 
> 

[snip]



Reply to: