LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 11-09-2013, 04:39 AM   #1
Boobless
LQ Newbie
 
Registered: Nov 2013
Posts: 4

Rep: Reputation: Disabled
Exact match removing via sed


hey all,

i got a script to delete line by search for match. but i noticed that it deletes any other match as well. i mean;

got a website need to be find: pornotane.org, script is deleting the line has pornotane.org

but also deletes line containing hdportane.org


command is here: sed -i '' -e "/$domain/d" file


any help will be appreciated
 
Old 11-13-2013, 04:24 AM   #2
Boobless
LQ Newbie
 
Registered: Nov 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
whatever guys, i have solved it. telling for people may have same problem:

i am running freebsd and my sed command doesn't have a function for exact match (word boundary </>), i've installed gsed and solved it.
 
Old 11-13-2013, 06:14 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I think you need to provide a little more information for it to be useful to others. Your first post would seem flawed.

If we can assume that the domain variable has the string 'pornotane.org' in it I do not believe sed will delete a line not containing that string ie. 'hdportane.org'.
Would you mind explaining a little further the original problem?

I was also curious about the 3 sets of quotes?? Is that just a typo?

Lastly, the -e is not required for only a single entry or was this culled from a larger sed statement and perhaps the cause of the original issue?
 
Old 11-13-2013, 06:28 AM   #4
Boobless
LQ Newbie
 
Registered: Nov 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
first, no it's not related to -e and the command is the from time i was trying anything to handle problem. Don't even remember what -e parameter is doing.

second, it is working as following

more file1.txt | while read LINE
do
domainLine=$(echo $LINE | awk '{printf $2}')

for domain in $domainLine
do
# echo $domain
grep $domain file
# sed -i "/$domain/d" file
gsed -i "/\b$domain\b/d" file
done
done

Last edited by Boobless; 11-13-2013 at 06:30 AM.
 
Old 11-13-2013, 09:13 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please use [code][/code] tags for your code snippets.

I would add that as you are parsing an entire file, without seeing its contents what could assume that both domains are listed in the file and hence why you were removing unwanted lines.
Remembering that a regex does not pick and choose what it matches and no addition of boundaries would assist in the issue.

Lastly, please remember to select he SOLVED option under thread tools if your solution has been found.
 
Old 11-14-2013, 12:13 AM   #6
Boobless
LQ Newbie
 
Registered: Nov 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
it is a bit hard to explain without writing down content of files. anyway, thank you for all your advices.
 
  


Reply



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
Using grep to find EXACT MATCH andy2008 Programming 19 02-14-2019 08:36 AM
exact match in awk cristalp Programming 20 09-19-2011 01:31 PM
[SOLVED] Match datetime by the minute (not an exact match by the second) [mysql] hattori.hanzo Programming 1 10-21-2010 05:43 PM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM
how to find an exact substring match? ldp Programming 7 02-22-2005 06:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 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
Open Source Consulting | Domain Registration