The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to delete a word from a file? ntgobinath Shell Programming and Scripting 4 06-04-2008 04:03 PM
how to delete spaces around a word sachin.gangadha UNIX for Dummies Questions & Answers 8 12-05-2007 04:00 AM
search& count for the occurence of a word skoppana UNIX for Dummies Questions & Answers 1 11-09-2007 05:07 PM
Count the number of occurence of perticular word from file rinku Shell Programming and Scripting 40 08-10-2007 07:33 PM
Sed help to delete everything prior to WORD drheams Shell Programming and Scripting 2 12-09-2005 05:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Thumbs up Delete all occurence of a word in one shot

i have a file called file1

cat file1
i am namish
namish lives in India
India and namish both are good.

I want to delete all the occurences of namish in one shot,if i do it with sed i guess all the lines will be deleted containing the pattern.Suggest me any idea without AWK.

Thanks
Namish
  #2 (permalink)  
Old 08-24-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
sed 's/namish//g' file1
  #3 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by robotronic View Post
Code:
sed 's/namish//g' file1
Thanks for the reply.

If i do not want the space at the place of the deleted pattern,what is suggested.
  #4 (permalink)  
Old 08-24-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
sed 's/ *namish *//g' file1
or

Code:
sed 's/^namish //g; s/ namish$//g; s/ namish / /g' file1
  #5 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Thanks robotronic!
  #6 (permalink)  
Old 08-24-2007
vishalzone2002 vishalzone2002 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 13
use vi editor and replace all occurances of namish with " "
  #7 (permalink)  
Old 08-24-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
Quote:
Originally Posted by vishalzone2002 View Post
use vi editor and replace all occurances of namish with " "
and what if there are 1000 occurances of namish in it? Then in command mode:
Code:
:1,$s/namish//g
Sponsored Links
Closed Thread

Bookmarks

Tags
sed, vim

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0