A question on SED

Hi Folks,

How do I pass a variable on sed (as a regular expression)???

I need to use a variable as a regexp in a sed command. The variable happens to be a time stamp which I fetch from another command.

To illustrate:

Suppose the value of variable var is....
var=10:20:22

I notice that this command doesn't work:

sed '1,/$var/d' textfile1

(I'm trying to delete the first line upto the first instance of var in the file textfile1.

Please help...tnx!

sed "1,/$var/d" textfile1

Use double quotes

Thanks very much...can you be so kind to show me the sed command if I wanted to delete from first line to the LAST INSTANCE of the variable... :slight_smile:

sed -n -e ":a" -e "$ p;N;/$var/d;b a" file