LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2011, 12:30 PM   #1
Drigo
Member
 
Registered: May 2009
Posts: 111

Rep: Reputation: 17
Angry Change a string recursively in files located in folders and subfolders


So, lets say I have a project that have generated lots of xml files. Though all these xml files point to a location with the text name TEXT15. I want to change all the files that containts TEXT15 and change it to TEXT16.

This actually works for files in a folder but not recursively in all the entire files....


perl -pi -c 's/TEXT15/TEXT16/g' ./*


but I have many subfolders and within this more subsub folders....i just want to do this recursively.
 
Old 07-22-2011, 12:49 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,819
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
Try the following:

Code:
#!/bin/bash
for i in $(find . -name *.xml)
do
        sed 's/TEXT15/TEXT16/g' $i
done
Please note that in order to make permanent changes in the files you need to add the -i flag to sed.
 
Old 07-22-2011, 01:21 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,508

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
I am guessing you could probably just use the find itself:
Code:
find . -name *.xml -exec sed 's/TEXT15/TEXT16/g' {} \;
 
  


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
[SOLVED] OpenSUSE 11.2 (KDE4): Take ownership of files, folders and subfolders in trash bin whschimmel Linux - Desktop 2 12-16-2010 02:42 PM
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 12:40 PM
Shell script to delete folders and files dynamically and recursively rjbaca Linux - General 1 06-21-2010 11:26 AM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
How to unzip files recursively inside folders? jessdog9001 Linux - Software 2 03-22-2006 12:59 PM


All times are GMT -5. The time now is 02:49 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration