[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Perl/C programmers, help pls


Here is a perl script that should do what you want (C is not really
suited to this kind of thing).


while (<STDIN>)


run it like:
$ cat small_file | ./filter_above > new_small_file

It is worthwile learning basic Perl, just to do simple things like this
(although you could also use sed).

To do all of the files in all of the subdirectories, you could probably
write a shell script to do it. Two ways I can think of would be to use
find to get a list of all of the files, and run them through this


for file in `find .`; do
    cat $file | ./filter > $file.new
    rm -f $file
    mv $file.new $file

Warning!!! Please test this on non-important data before running it on
your 30000 files. I'm claim no responsibility for what it does to your
system. If something does go wrong, the 'rm -f $file' line will delete
your data for good, and without asking (maybe remove the -f until you're
sure its working okay). You have been warned!

The other way would be to write some funky script that recursively
traverses directories, converting each file in that directory as it
goes. This is left as an exercise for the reader (would be more
complicated than the above script anyway... you can do it out of
geek-curiosity :)


"Chad A. Adlawan" wrote:
>      can someone please help me with a script w/c searches the contents of all those small files and looks for __" and then replaces them with __"http://www.pexchange.com/__ ?
> thanks a lot in advance,
> chadi

Reply to: