LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed not working for loop (https://www.linuxquestions.org/questions/programming-9/sed-not-working-for-loop-938244/)

say_hi_ravi 04-05-2012 04:24 AM

sed not working for loop
 
$sed -i '/abcd/d' file1

this works - deletes the line containing abcd in file1

but below does not work

$i='ab bc cd de'
$for j in $i;do sed '/$j/d' file1;done

This loop do not delete lines containg ab,bc,cd,de. Any help?

druuna 04-05-2012 05:01 AM

Hi,

You are using single quotes in the sed part, change those to double quotes:
Code:

i='ab bc cd de'
for j in $i; do sed "/$j/d" file1; done

Hope this helps.

say_hi_ravi 04-05-2012 05:10 AM

Thanks druuna..

druuna 04-05-2012 07:03 AM

You're welcome :)

BTW: Can you put up the [SOLVED] tag.
first post -> Thread Tools -> Mark this thread as solved


All times are GMT -5. The time now is 07:58 PM.