LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-05-2012, 04:24 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 68

Rep: Reputation: 15
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?
 
Old 04-05-2012, 05:01 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
1 members found this post helpful.
Old 04-05-2012, 05:10 AM   #3
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 68

Original Poster
Rep: Reputation: 15
Thanks druuna..
 
Old 04-05-2012, 07:03 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
You're welcome

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - loop construct for text processing danielbmartin Programming 5 01-24-2012 09:42 PM
[SOLVED] sed loop gives unexpected results jgombos Programming 13 09-10-2011 12:33 AM
Changing sed in loop rickard.solsjo Linux - Newbie 2 02-21-2011 03:46 AM
[SOLVED] sed in a bash loop with ascending output gary_in_springhill Programming 20 01-14-2011 10:35 AM


All times are GMT -5. The time now is 08:12 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration