1834798 Members
2653 Online
110070 Solutions
New Discussion

sed

 
SOLVED
Go to solution

sed

Hello all,

Just been looking into forum but couldn't find what I am looking for. I need to extract the content from a file that is between { } from any of these strings.

${C123QHOME}
${C12QHOME}

Or anything else between { } and drop that to a variable. I know that sed would do it but just can't start... any help?

So let's say ${C124HOME} would become C124HOME into a variable and then:

echo MYVAR
C124HOME
5 REPLIES 5
Sandman!
Honored Contributor

Re: sed

# cat infile
${C124HOME}

# MYVAR=$(sed 's/.*{\(.*\)}.*/\1/p' infile)

# echo $MYVAR
C124HOME
spex
Honored Contributor

Re: sed

# MYVAR=$(tr -d '${}' < infile)

Re: sed

Ok but it gives me other stuff since there are some other string inside the file that has {} sign. The string always finished by HOME}, like :

cd ${C124HOME}
cd ${CAAHOME}
cd ${CAAQHOME}

I want to make sure I get only what could be inside ${***HOME}. All .profile files has that command :

cd ${***HOME}
ie.
cd ${CAAHOME}
or
cd ${CAAQHOME}
or
cd ${TCEHOME}

Tks
Sandman!
Honored Contributor
Solution

Re: sed

# sed -n '/HOME}/s/.*{\(.*HOME\)}.*/\1/p' infile

Re: sed

Tks for your help. That is exactly what I was looking for..