Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-31-2009, 12:29 PM   #1
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, 01:36 PM   #2
Registered: Sep 2007
Location: SF Bay Area, CA
Distribution: CentOS, SLES 10+, RHEL 3+, Debian Sarge
Posts: 159

Rep: Reputation: 32
You can try:
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.


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

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

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