The command below does not work. what I am doing wrong ?
For some reason second part of the xargs command is not does what I expect
If I get this working I intend to use it for multiple file rename later.
(here i put a "echo" just to display the command so that you can check it behaves has expected, if ok, then just remove the 'echo' and rerun the 'for' loop with the real cp command
{} is not expanded by the shell. It is expanded by xargs after it starts executing. However, xargs cannot be exec'd until all of its command line arguments are known. This requires the shell to invoke a subshell to perform the command subsitution in backticks. Note that at this point xargs is not running. echo {} will always yield nothing but {}. In AWK, the sub() function has nothing to do since there's no DP1 to replace, and the output is the same as what's echoed. Then the shell, finally knowing the result of the command substitution, can execute xargs. xargs will then always be passed {} {} as its final two parameters.
---------- Post updated at 05:07 PM ---------- Previous update was at 04:51 PM ----------
The code I ended up with!
#!/bin/ksh
for i in *.dbf
do
echo
echo "... renaming $i to ${i/DP1/TML}"
echo -e "y - continue / n - Skip / Ctrl+C - abort --> \c"
read ans
if [ "$ans" = "y" ]; then
mv $i ${i/DP1/TML}
else
echo skipping $i
fi
done