Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-18-2009, 01:51 PM   #1
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 48
Remove exact matching word using sed

I have a file which has the words "splashimage and "splash". I would like to remove the word only "splash" from everywhere.

Using the following command:
sed "s/splash//g"
also removes the "splash" part from "splashimage", which I don't want. I just want to replace the word match exactly i.e. "splash".

Googled a bit and found these:

but not exactly what I am looking for.

Old 08-18-2009, 02:05 PM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734
You can use the "word boundary" notation (\<...\>). Using your example:
sed 's/\<splash\>//g'
Note that I also used single quotes. It is normally good practice to do this by default, and then change to double quotes when needed.

Last edited by pixellany; 08-18-2009 at 02:06 PM.
Old 08-20-2009, 05:15 PM   #3
Senior Member
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48

Thanks that worked!


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
matching a pattern in a file & prefixing a word shivarajM Linux - Software 3 05-28-2009 01:14 PM
command for grep the exact word nagendrar Linux - Newbie 7 04-29-2009 02:33 PM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 06:53 PM
sed matching an apostrophe dazdaz Linux - General 2 04-28-2006 05:24 PM
please read it i dont know the exact word to use to describe wat i wanna say pranith Slackware 5 05-30-2005 07:27 AM

All times are GMT -5. The time now is 01:04 PM.

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