LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
Search this Thread
Old 07-29-2005, 10:00 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
search and replace in every file


hiho@ll

how can i make a search and replace in every file?

i read something about awk, but it didn't work for me because i don't to few about awk
all i got was an empty file!

well i just want to search for a string and replace it with another string

every string in every file of a subfolder

thx@ll
 
Old 07-29-2005, 10:24 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Take a look here:

http://www.linuxquestions.org/questi...hreadid=346190

A thread I answered with the same contants.

Hope this helps.
 
Old 07-30-2005, 05:07 PM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Code:
perl -pi.bak -e 's/some_string/new_string/g'  dir/*
will replace "some_string" with "new_string" in every file in the dir subdirectory, preserving the original files with a ".bak" suffix.
 
Old 07-30-2005, 06:50 PM   #4
clausi
Member
 
Registered: Mar 2004
Distribution: Debian
Posts: 48

Rep: Reputation: 15
Althought the perl oneliner is sufficient, beginners may like to try Regexxer.

The advantage is a preview and a one-by-one replace which is helpful for more complicated regular expressions.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 01:13 AM
Looking for a multiple file search and replace tool, prefer graphical haimeltjnfg Linux - Software 6 02-02-2005 11:53 PM
Script to search and replace in text file - kinda... jeffreybluml Programming 45 11-07-2004 06:37 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 11:11 AM
Multi-file search and replace? miknight Linux - General 4 10-21-2003 07:45 PM


All times are GMT -5. The time now is 12:35 AM.

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