Find, replace, file path in multiple files for Solaris 10

Guys I have a big issue that I need to get fixed ASAP however I can not seem to find a way to do it. We started to use zones with Solaris 10 at work and we moved a zone from a SIT box to a DEV box. Problem is the software we have installed is looking at a /lcl/sit/apps/ path and it needs to look at /lcl/dev/appsl path instead.

I know how to do a search and replace of multiple files in a directory and all sub dirctories with PERL using....

perl -e "s/sit/dev/g;" -pi $(find /lcl/dev/apps/Tivoli/test/test -type f)

The problem with doing it this way is that it uses / characters and since I need to replace part of a path that causes an issue. Plus any word in any of the files that would have "sit" would be replaced with "dev".

I need to find a way through something like a bash script or something that can run on Solaris 10 that can do a search of all files contents from a specific directory and all sub directory for...

/lcl/apps/sit

And replace

/lcl/apps/dev

This way event it if found a word like for example "sitting" it would not replace it with "devting"

I hope I am giving enough detail here :slight_smile: I have been on Goolge all morning and I just can not seem to find a way that works with Solaris 10.

Thank you in advance!

I guess you can just escape slashes with backslashes in perl like:

perl -e "s/\/lcl\/apps\/sit/\/lcl\/apps\/dev/g;" -pi $(find /lcl/dev/apps/Tivoli/test/test -type f)

?

Will that also follow all sub directories? That was the one part I was not sure on. I need it to. Thank you very much for the help.

---------- Post updated at 04:08 AM ---------- Previous update was at 04:02 AM ----------

Well that might not work. I am getting....

:/lcl/dev/apps/Tivoli>perl -e "s/\/lcl\/sit\/lcl\/dev/g;" -pi $(find /lcl/dev/apps/Tivoli/tipv2 -type f)
bash: /usr/bin/perl: Arg list too long

Not shocked as there are a ton of files that need to have this path replaced. Any ideas guys? Thank you again.

You could hand over the found files with xargs to perl:

find /lcl/dev/apps/Tivoli/test/test -type f| xargs -n1 -I {} perl -e "s/\/lcl\/apps\/sit/\/lcl\/apps\/dev/g;" -pi {}

---------- Post updated at 03:11 PM ---------- Previous update was at 02:27 PM ----------

find is recursive, yes.

1 Like

That did the trick. Thank you! Big help.

Are you sure you want to replace a path in a ton of files? That's a bit dangerous I'd say. Can't you just set-up a symlink so that the old path is still valid?

Regards,
Mark.