I have a directory A with a bunch of files with .xml
extension that I need to run a search-and-replace on. There are a couple of symlinks (also with .xml
extension) in A that link to certain files in A. I tried running sed -i 's/search_regexp/replacement_string/' *.xml
but when it hits a symlink it fails with
sed: ck_follow_symlink: couldn't lstat file.xml: No such file or directory
A solution would be to loop around the files that I actually want to modify and call sed on each file, but is there a way to tell sed to ignore symlinks? or just follow them and modify the linked file?
@piokuc already named the option for following symlinks, here's how you can ignore them with find
first:
find /path/to/dir/ -type f -name "*.xml" ! -type l -exec sed -i 's/search_regexp/replacement_string/' {} \;
or, slightly more efficient:
find /path/to/dir/ -type f -name "*.xml" ! -type l | xargs sed -i 's/search_regexp/replacement_string/'
The ! -type l
part means "not anything that is a symlink"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With