LinuxQuestions.org
Register a domain and help support LQ
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 05-17-2006, 09:55 AM   #1
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 54
Question Change a string in all files in a directory?


Hey guys,

I'm trying to clean up a ton of code I wrote on another platform. I want to do a global change from stringa to stringb in every file in a directory, but I don't know what to use or how to use it. I could pull them up in emacs and do it but that will take forever. Virtual icy-cold 6-pack of your favorite ale to the guy who gives me the secret formula

Thanks,
Rand
 
Old 05-17-2006, 10:09 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,944

Rep: Reputation: Disabled
Try this:
Code:
> sed -i~ "s/stringa/stringb/g" *
This will make a backup of all of the files in case something goes wrong. Do you have variants of "stringa" in the code, such as "MYstringa" or "stringalpha"? If so, the command above will change those also. If you don't want that to happen, I'll show you how to do that.
ta0kira

Last edited by ta0kira; 05-17-2006 at 10:10 AM.
 
Old 05-17-2006, 11:47 AM   #3
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Original Poster
Rep: Reputation: 54
Awesome! It ran so fast I couldn't believe it worked! I took off the ~ because I didn't want to create backups. Thanks a lot!

What'll it be? Some ice cold....?

Rand
 
  


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
Which directory contains files that normally change their size frequently? Simon Adebisi Linux - Software 4 06-28-2005 03:37 PM
need script to copy all files containing a certain string to a directory dc6463 Programming 12 06-13-2005 09:45 AM
chmod command to change all files in directory paul_mat Linux - Newbie 2 01-10-2005 09:05 PM
Script to change names of files in a directory geomonap Linux - General 2 12-03-2004 03:04 PM
Find string pattern in directory of text files magnum818 Linux - Newbie 2 10-15-2003 08:19 PM


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