sed not working while passing the variable to print

Hi

I have below sed to search and print particular line that matches in file and prints it, which is actually working fine as expected.

sed -n "/^2012-11-19 23:[0]*/p" filename

but if I replace date with the variable it seems it's not recognizing it and throwing out error

 v="2012-11-19"
sed -n 's/^'$v' 23:[0]*/p"  filename
 sed -n "s/^$v 23:[0]*/p"  filename

so can anyone help me resolving this??

Try

v="2012-11-19" 
sed -n '/^'"$v"' 23:[0]*/p'  filename

hey pamu,

that was my mistake, actually there was (') instead of (") in my first sed with variable one you pointed out.

thanks for pointing out.

But anywas, I followed your suggestion and tried to execute as below

sed -n 's/^'"$v"' 23:[0]*/p' filename

then it pops up with

sed: -e expression #1, char 23: unterminated `s' command

error message

Please look at my post again. You won't find s there.:slight_smile:
And i have highlighted s also in your previous code in red.(check post 2)

pamu

thats so stupid of me, I have no idea why in the first place I even put s.
sorry for this!!

now all good..