Unix Programming - Newbie Question - Sed in all directories (including subs)

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2006 > Newbie Question - Sed in all directories (including subs)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Newbie Question - Sed in all directories (including subs)
webspazz@san.rr.com

2006-06-23, 7:32 am

I am using the following to change file extensions. Can anyone tell me
if I can modify this to change all files including all in every
sub-directory? Thanks

for file in *.asp ; do mv $file `echo $file | sed
's/\(.*\.\)asp/\1php/'` ; done

Sjoerd

2006-06-23, 7:32 am


webspazz@san.rr.com wrote:
> for file in *.asp ; do mv $file `echo $file | sed
> 's/\(.*\.\)asp/\1php/'` ; done


Take a look at "find":
for file in `find . -name *.asp`

Duncan Muirhead

2006-06-23, 7:32 am

On Fri, 23 Jun 2006 02:06:49 -0700, webspazz wrote:

> I am using the following to change file extensions. Can anyone tell me
> if I can modify this to change all files including all in every
> sub-directory? Thanks
>
> for file in *.asp ; do mv $file `echo $file | sed
> 's/\(.*\.\)asp/\1php/'` ; done


I'd recommend "man find".
For example you could (I think) replace ".asp" above with
`find . -name "*.asp"` (note the back quotes)
or you could replace the for with a find (using the -exec action to
execute your sed)
Duncan


Robert Harris

2006-06-23, 1:22 pm

webspazz@san.rr.com wrote:
> I am using the following to change file extensions. Can anyone tell me
> if I can modify this to change all files including all in every
> sub-directory? Thanks
>
> for file in *.asp ; do mv $file `echo $file | sed
> 's/\(.*\.\)asp/\1php/'` ; done
>

For the rename, you could do:

mv $file ${file%.asp}.php

instead of invoking sed.

Robert
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com