LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-24-2007, 11:31 PM   #1
AlanL
Member
 
Registered: Dec 2002
Location: New Westminster, B.C.,CANADA
Distribution: Slax. Tinycore. Puppy.
Posts: 109

Rep: Reputation: 15
Replace word in file-mulitple times.


I need to replace a word in a file 154 times.
What program and what command would I use?
 
Old 06-24-2007, 11:41 PM   #2
Findus
Member
 
Registered: Nov 2006
Distribution: Fedora 8
Posts: 64

Rep: Reputation: 15
Can you open the file in a text editor? If that is an option, you can use the "search and replace"-function, found under the Edit-menu. Most text editors have that function, so it shouldn't be too hard to find.

- Delphi
 
Old 06-24-2007, 11:57 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
You can use sed for that. Does it have to be 154 times or was that a generalisation? If you want to replace every occurrence of the word dog with cat in the file test-data and put the results in a file called test-data.new, you can do this:
Code:
sed -e 's/dog/cat/g' test-data > test-data.new
It then becomes a process of checking the data. For example, the word Dog won't be changed because of the capital D. Have a look at the man page for sed or google for sed howto tutorial for more info.
 
Old 06-25-2007, 12:03 AM   #4
got_nix
Member
 
Registered: Oct 2004
Location: Jamaica
Distribution: Ubuntu 6.0.6 (Dapper Drake)
Posts: 59

Rep: Reputation: 15
sounds like a good ole find and replace will fix his problem control + h n its easy street from there on out.
 
Old 06-25-2007, 01:49 AM   #5
AlanL
Member
 
Registered: Dec 2002
Location: New Westminster, B.C.,CANADA
Distribution: Slax. Tinycore. Puppy.
Posts: 109

Original Poster
Rep: Reputation: 15
Thanks gilead...that command worked OK.
 
Old 06-25-2007, 02:14 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by got_nix
sounds like a good ole find and replace will fix his problem control + h n its easy street from there on out.
Which app is that with? :}


Cheers,
Tink
 
  


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
tcsh script, replace word in file true_atlantis Programming 10 02-17-2006 01:24 PM
find and replace answer word? matarodi Linux - General 0 10-27-2005 01:51 PM
replace a word in vim editor fssengg Linux - Newbie 3 03-10-2005 08:39 AM
Replace word in VIM ICO Linux - Software 2 03-17-2004 01:28 AM
How to replace a word within a file elegantly Linh Programming 3 10-23-2003 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:03 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