LinuxQuestions.org
Help answer threads with 0 replies.
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, 02:51 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,242

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, 03:05 PM   #2
pixellany
Guru
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch+KDE
Posts: 16,552

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
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 03:06 PM.
 
Old 08-20-2009, 06:15 PM   #3
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,242

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 02:14 PM
command for grep the exact word nagendrar Linux - Newbie 7 04-29-2009 03:33 PM
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 07:53 PM
sed matching an apostrophe dazdaz Linux - General 2 04-28-2006 06: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 08:27 AM


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