I want to do the equivalent of:
for i in `ls -1`; do echo $i | mv $i `sed 's/profile/account/'`; done
with xargs
ls -1 | xargs -I{} mv {} `echo {} | sed 's/profile/account/'`
But the sed
after the pipe within backticks is ignored.
Anyone know why that's the case?
Edit: More info
The root problem is simply to rename files in a directly given a pattern replacement (here replace profile
with account
, however that is solved with for in
loop over the files.
The question I'm posing is why is the following not working.
ls -1 | xargs -I{} mv {} `echo {} | sed 's/profile/account/'`
Why does the
`echo {} | sed 's/profile/account/'`
portion not return the replaced filename but the original filename. It's as if the |
doesn't work inside the backticks.
To write the problem differently:
If I have a list like in a file called list.txt
profile1.txt
profile2.txt
And want to generate
account1.txt
account2.txt
While operating on each individual line separately so I can run a command on it.
cat list.txt | xargs -I{} echo `echo {} | sed 's/profile/account/'`
Why does command return:
profile1.txt
profile2.txt
Instead of changing profile to account?