HOw can I use any variable in sed command.
For example I am using 'sed -e 's/?/$ORACLE_HOME/g' $file_name
Here it replaces ? with $ORACLE_HOME. Instead of it I need actual value of $ORACLE_HOME. How can I do that?
Please advice.
Thanks in advance.
Malay
quote them to substitute
sed -e 's/abc/'$ORACLE_HOME'/g' <filename>
==> sed -e 's/?/'$ORACLE_HOME'/g' dest.log
sed: command garbled: s/?//diqr001/opt/tools/oracle/product/9.2.0/g
Not working.
Malay
ORACLE_HOME u had provided contains "/"
when substituting with sed
they have to be disabled with a "\"
following is just an example
echo "abc" | sed -e 's/abc/\/diqr001\/opt\/tools\/oracle\/product\/9.2.0/'
change ur script accordingly
vino
5
Wouldn't double-quoting solve the sed expression work ?
sed -e "s/abc/$ORACLE_HOME/g" <filename>
But how can I replace '/' in $ORACLE_HOME with '\/'?
Malay
vino
7
Is
sed -e "s/?/$ORACLE_HOME/g" $file_name
working ?
Ygor
8
Any character (other than backslash or newline) can be used instead of a slash to delimit the regular expression and the replacement.
sed -e "s:?:$ORACLE_HOME:g" $file_name
Thanks very much. Its resolved.
But that rule doesn't work when I try to delete a line. Like following code doesn't work:
sed ":$ORACLE_HOME: d" $file_name
Simply following works alright
sed '/text/ d' $filename
but not this
sed ':text: d' $filename
So how do I delete a line using variables that contain slashes?
era
11
You can use any delimiter in the search string too, but you have to backslash it (don't ask me why).
sed '\:text:d' $filename
Thank you era for fast reply. And that works!
Thanks again.
hi i have a big file i need every time to cut number of lines related together and ta delete also first two lines in the file.
for example :
while ( $x <= $n)
set var1 = ` cat file | sed '1,2d' | awk '{print $4}' | sed '$x,$d' `
@ x = $x + $t
end
it gives me an error with sed command which contains the variable ??????
can anyone help me!!!!!!!!!!!!!!!!!!!!