LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 08-18-2009, 01:51 PM   #1
kushalkoolwal
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:
Code:
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:
http://dbaspot.com/forums/shell/3905...ctly-word.html

http://groups.google.com/group/VGLUG...739d55b96a87d1

but not exactly what I am looking for.

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

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
You can use the "word boundary" notation (\<...\>). Using your example:
Code:
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
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Solved

Thanks that worked!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 02:23 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