I'm trying to change a string in multiple text files (configurations migrated to other user). I used this command:
grep -iIlr "/home/user/.local" | xargs sed -i 's/\/home\/user\/\.local/~\/\.local/g'
also tried this:
grep -iIlr "/home/user/.local" | xargs -d '\n' sed -i "s/\/home\/user\/\.local/~\/\.local/g"
They don't work. Errors is produced by sed, the output of the command is:
sed: can't read dir/file1: No such file or directory
sed: can't read dir/file2: No such file or directory
...
sed: can't read dir/file99: No such file or directory
The error is produced for every file (99 in total). The dir/file1..99 returned is valid, it's the proper path and filename for the files.
grep alone produces the proper list of files. No special characters on file names, I think not spaces also (not fully certain about this). Isn't xargs passing a proper list?
OS: RHEL 8.10 fully updated,
GNU grep v 3.1,
GNU sed 4.5,
xargs (GNU findutils) 4.6.0
Adding the output (sample last lines) of grep -iIlr "/home/user/.local" command.
pwd, ~/.local/pipx
venvs/pipx/bin/pipx
venvs/pipx/bin/activate.fish
venvs/pipx/bin/activate-global-python-argcomplete
venvs/pipx/bin/activate.csh
venvs/pipx/pyvenv.cfg
venvs/pipx/lib/python3.11/site-packages/pipx_shared.pth
shared/bin/pip3.11
shared/bin/activate
shared/bin/pip3
shared/bin/pip
shared/bin/wheel
shared/bin/activate.fish
shared/bin/activate.csh
shared/pyvenv.cfg