sed block search with variables
Hi Folks,
1) extracting a block of text from file1 to file2 works fine this hardcoded way: sed -n '/DW/,/;/p' file1.tmp > file2.tmp 2) Now I need it more flexible using a shell variable: p=DW sed -n '/$p/,/;/p' file1.tmp > file2.tmp But the file2.tmp stays empty. What is wrong ? Thank you all. |
The single quotes prevent shell substitution and the string $p is passed literally to sed and interpreted with its own rules. To let the shell make the substitution and expand the value of the variable, use double quotes.
|
double quotes
Colucix,
thanks for your reply. I tried several double quotes but no joy. How should that look like in my case ? cheers from Germany :-) |
This works on my system:
Code:
sed -n "/$p/,/;/p" file |
Thank you ! That is the solution. Have a great day. :-)
|
All times are GMT -5. The time now is 07:01 AM. |