Taking sed result in a variable

Hi All,

How can i take the following code having three seds into a variable :

echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/[0-9]+/g' | sed 's/\#/'$job_date'/g'

I want to get the result stored in a script variable

i tried

var2=`echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/[0-9]+/g' | sed 's/\#/'$job_date'/g'`

but didnt work

Define 'did not work'

export myvar=""

echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/[0-9]+/g' | sed 's/\#/'$job_date'/g' | read myvar

echo "$myvar"

Hi ,

This is not working

---------- Post updated at 10:43 AM ---------- Previous update was at 10:32 AM ----------

Hi All,

If i do

echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/[0-9]+/g' | sed 's/\#/'$job_date'/g'

i get the right format in the out put that is

EGZAFU01\\.DOXR\\.UK\\.01\\.25112009\\.S001\\.V1\\.D[0-9]+\\.data\\.txt

but if i use the code which gets the value in a variable that is :

var2=`echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/[0-9]+/g' | sed 's/\#/'$job_date'/g'`

the var2 variable gets following value :

EGZAFU01\.DOXR\.UK\.01\.25112009\.S001\.V1\.D$\.data\.txt[0-9]+

As you can see the $ has not been replaced with [0-9]+ and the "\\" have changed to '\

first, you can do that in a single sed command, usig the -e flag :

VAR=`echo "$DateFileFormat" | sed -e 's/\./\\\\./g' -e 's/\$/[0-9]+/g' -e 's/\#/'$job_date'/g'`

Now, your problem comes probably from posix parameter set to on in your shell, type a man sed to see the regex possibilities.
try "--regexp-extended" or "-r", maybe it works.

var2=$(echo "$DateFileFormat" | sed "s/\./\\\\\\\\./g;s/\\\$/[0-9]+/g;s/\#/$job_date/g")
$> echo $var2
EGZAFU01\\.DOXR\\.UK\\.01\\.25112009\\.S001\\.V1\\.D[0-9]+\\.data\\.txt

---------- Post updated at 23:25 ---------- Previous update was at 23:16 ----------
ksh/bash:

var=${DateFileFormat//\./\\\\.}
var=${var//$/[0-9]+}
var=${var//#/$job_date}
$> echo $var
EGZAFU01\\.DOXR\\.UK\\.01\\.25112009\\.S001\\.V1\\.D[0-9]+\\.data\\.txt