LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-31-2009, 01:29 PM   #1
nushki
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Rep: Reputation: 0
shell script, sed


there are file1 and file2, i need to delete each line of file2 in file1 only ONCE.

if i write

while read line ; do sed -i "/$line/d" file1; done < file2

it deleted not one $line in file1, but all, and i need anly one.

Could you please help me.
 
Old 03-31-2009, 02:36 PM   #2
kenoshi
Member
 
Registered: Sep 2007
Location: SF Bay Area, CA
Distribution: CentOS, SLES 10+, RHEL 3+, Debian Sarge
Posts: 159

Rep: Reputation: 32
You can try:
Code:
while read line; do sed -i -re '0,/'"$line"'/s///' -e '/^$/d' file1;done < file2
There's probably more elegant ways of doing this, just off the top of my head, hope this helps.
 
  


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
awk sed shell script slcalice Programming 3 03-09-2009 06:40 AM
Shell Script , using Sed mogra Linux - Newbie 8 05-07-2008 02:18 PM
Using sed in a shell script RobHill Linux - General 4 05-29-2007 04:31 PM
Sed shell script question pete1234 Programming 4 08-18-2006 10:15 PM
shell script problem on sed. chooi Programming 3 02-11-2006 12:35 AM


All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration