Re: FAQ question
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 04/27/05
- Next message: Ed Morton: "Re: Script to insert text before a certain line"
- Previous message: Gnarlodious: "Script to insert text before a certain line"
- In reply to: Bruce Barnett: "Re: FAQ question"
- Next in thread: Bruce Barnett: "Re: FAQ question"
- Reply: Bruce Barnett: "Re: FAQ question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 27 Apr 2005 11:12:33 -0500
Bruce Barnett wrote:
> Ed Morton <morton@lsupcaemnt.com> writes:
>
>
>> g) awk '$0 == '"$svar"'' file
>
>
> I think it's worth highlighting this technique, because it works for
> any utility with any shell.
But it's evil and must be stopped ;-). Seriously, though, even though it
may be necessary for other utilities it is way down in the list of ways
to pass variables to awk since every newer awk provides better alternatives.
I usually tell people about this technique
> first, because of this. If you need to pass a variable into sed, for
> instance, this is the technique I usually use.
In 25 years of using sed I've never done that. I just use double quotes
around the whole script:
PS1> echo "a${HOME}b" | sed 's?'"$HOME"'?p?'
apb
PS1> echo "a${HOME}b" | sed "s?$HOME?p?"
apb
since it's shorter to type and easier to read.
> Perhaps you can have a section that discusses passing variables into a
> generic utility, and then have the awk section mention the previous
> options, and then give those options that only AWK supports.
I don't want to do that because:
a) I don't know enough about that topic to write a FAQ on it.
b) I've never seen that question raised so it'd probably be
inappropriate for a FAQ.
c) I'm just trying to straighten the record on how to pass variables to
awk specifically since it is a FAQ in several NGs and there's no
accurate answer anywhere I can find today.
d) My answer is already much longer than I'd have liked.
Ed.
- Next message: Ed Morton: "Re: Script to insert text before a certain line"
- Previous message: Gnarlodious: "Script to insert text before a certain line"
- In reply to: Bruce Barnett: "Re: FAQ question"
- Next in thread: Bruce Barnett: "Re: FAQ question"
- Reply: Bruce Barnett: "Re: FAQ question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|