[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I get data from an environment variable in sed SCRIPT FILE?
From: |
Bob Proulx |
Subject: |
Re: How can I get data from an environment variable in sed SCRIPT FILE? (under MS-DOS, not UNIX) |
Date: |
Fri, 24 Oct 2008 15:02:54 -0600 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
krondor@solupia.co.kr wrote:
> Is there no way to use myTemp_Value in mySedScript.TXT ??
> as far as i know, an environment variable is available in unix.
As far as I know there isn't a way to retrieve environment variables
inside of sed scripts even on the most delightful GNU and Unix
platforms. AWK or Perl or Python or Ruby would generally be
recommended in that case since those do have that capability. I would
probably use the shell to create the sed script with the variables
already expanded.
> I'm using GNU SED for windows
I am not a user of ms-windows and so do not know very much about it
but I wanted to talk about the use of sed on GNU and Unix.
> and made a batch file like this...
> Set myTemp_Value="Hello world"
> SED -n -f mySedScript.TXT targetFile.TXT
> but...
> How can i use DOS Environment variable in SED Script File?
If you can also use bash for the script shell then have bash expand
the variables in the script before calling sed.
#!/bin/sh
VAR1=foo
VAR2=bar
cat >mySedScript.TXT <<EOF
s/$VAR1/$VAR2/g
EOF
sed -n -f mySedScript.TXT targetFile.TXT
Bob