Sponsored Content
Top Forums Shell Programming and Scripting Replace string in all files in a folder and subfolders. Post 302208710 by crazynups on Tuesday 24th of June 2008 03:58:05 PM
Old 06-24-2008
Quote:
Originally Posted by danmero
Code:
for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z && rm temp;
done

Thanks it worked


need some more guidence

i also need to make changes according to file types like this

Code:
for z in `find . -type f -name "*.PHP"`; do
sed -e 's@123@456@g' $z>temp;
mv temp $z && rm temp;
done

for z in `find . -type f -name "*.html" -o -name "*.htm"`; do
sed -e 's@abc@xyz@g' $z>temp;
mv temp $z && rm temp;
done

any other better way to do this instead of using 2 loops?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic Q: getting list of all files of type within folder & subfolders

A painfully rudimentary UNIX question for somebody. I've been puzzling over this for the last hour but can't find the right command. I'm simply trying to get a list of all files - and their full paths - within a folder & subfolders which have extension .php and .js. That's it! No amount of... (1 Reply)
Discussion started by: AtomicPenguin
1 Replies

2. UNIX for Dummies Questions & Answers

How to learn the number of files under a particular folder, containing subfolders

Hi ALL I would like know how many files there under a particular folder, which contains subfolders. Thanks (5 Replies)
Discussion started by: cy163
5 Replies

3. Shell Programming and Scripting

Shell script delete log files from folder & subfolders on space usage

Hi, I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes. I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
Discussion started by: saha
3 Replies

4. Shell Programming and Scripting

Replace last 2 folder directory string with sed

Hi guys, I´m trying to replace the 2 last folders name in a list of directories with a new string, but I´m don´t know which regex to apply. Directories list: C/my user/documents/games & music C/my user/documents/photos 09-24-2008 C/my user/settings/config ?1_2 * The last folder may have... (11 Replies)
Discussion started by: cgkmal
11 Replies

5. UNIX for Dummies Questions & Answers

How to obtain a count of files in a folder and it's subfolders

First of all, the extent of my unix knowledge is next to nil. I've been able to telnet to a unix box, and thanks to the Computer Hope website, I've been able to learn a few basic commands to navigate from folder to folder, and view contents. What I really need to do is obtain a count of all... (2 Replies)
Discussion started by: scarfinv
2 Replies

6. Shell Programming and Scripting

To replace a string in file by its parent folder name.

Hi all, I have a directory structure like "folder1/folder2/website_name/folder3/folder4/file.php." I need to write a script which will enter into file.php and replace a particular string of characters with "website_name" folder name. In folder2,there are many such website's folders kept.So... (4 Replies)
Discussion started by: arien15488
4 Replies

7. Shell Programming and Scripting

Search in folder and subfolders

How can this be done? I mean, I want to search for all *png *jpg *bmp files in my ~/Pictures/ folder....How can I list them? Thank you geeks :) :b: (2 Replies)
Discussion started by: hakermania
2 Replies

8. Homework & Coursework Questions

unique words in files of folder and its subfolders

Hello, I tried to count all unique words of all files in one folder and its subfolders. Can anybody say me, why this doesnt work: ls| find -d | cat | tr "\ " "\n"| uniq -u | wc -l ??? Cat writes only the names of those files, but not the wors, which should be in them. Thanks for any advice. ... (9 Replies)
Discussion started by: Dworza
9 Replies

9. UNIX for Dummies Questions & Answers

Search current folder and subfolders with grep

Hello, Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files) Any suggestions... Using SunOS 5.9 Thanks, Trinanjan. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

10. Shell Programming and Scripting

Splitting a folder containing different files into subfolders

I have a folder with 4000 (*3) files like gr_q4_gb-1.anc gr_q4_gb-1.anc_cdr_st.txt gr_q4_gb-1.anc_cdr_tr.txt gr_q4_gb-2.anc gr_q4_gb-2.anc_cdr_st.txt gr_q4_gb-2.anc_cdr_tr.txt gr_q4_gb-3.anc gr_q4_gb-3.anc_cdr_st.txt gr_q4_gb-3.anc_cdr_tr.txt . . gr_q4_gb-4000.anc... (6 Replies)
Discussion started by: sammy777888
6 Replies
Test::Folder(3pm)					User Contributed Perl Documentation					 Test::Folder(3pm)

NAME
Test::Folder - test folder attributes SYNOPSIS
use Test::More ...; use Test::Folder; DESCRIPTION
This modules provides a collection of test utilities for folder attributes. Use it in combination with Test::More in your test programs. FUNCTIONS
folder_exists_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder exists, and not ok otherwise. folder_not_exists_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder does not exist, and not ok otherwise. folder_empty_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is empty (contains no files or subfolders), and not ok otherwise. folder_not_empty_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is not empty (contains any files or subfolders), and not ok otherwise. folder_readable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is readable, and not ok otherwise. folder_not_readable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is not readable, and not ok otherwise. folder_writable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is writable, and not ok otherwise. folder_not_writable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is not writable, and not ok otherwise. folder_executable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is executable, and not ok otherwise. folder_not_executable_ok(FOLDERNAME [, TESTNAME] ) Ok if the folder is not executable, and not ok otherwise. TO DO
There are probably some more folder attributes that can be tested. If you need them, please ask (or better yet, contribute code!). AUTHOR
Martin 'Kingpin' Thurn, "mthurn at cpan.org", <http://tinyurl.com/nn67z>. BUGS
Please report any bugs or feature requests to "bug-test-dir at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Dir>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Test::Folder You can also look for information at: o RT: CPAN's request tracker <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Dir> o AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/Test-Dir> o CPAN Ratings <http://cpanratings.perl.org/d/Test-Dir> o Search CPAN <http://search.cpan.org/dist/Test-Dir> ACKNOWLEDGEMENTS
COPYRIGHT &; LICENSE Copyright (C) 2007-2008 Martin 'Kingpin' Thurn This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2011-02-20 Test::Folder(3pm)
All times are GMT -4. The time now is 03:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy