I have two files:
~/Pulpit/kot$ find . -name "*jpg" -printf "%f\n"
1.jpg
`[~!($%^_&*){.}\___"`]`1.jpg
I want to change their name to:
_home_pic_Pulpit_kot_1.jpg
_home_pic_Pulpit_kot_`[~!($%^_&*){.}\___"`]`1.jpg
I use this command:
~/Pulpit/kot$ find $PWD -name "*.jpg" | mawk '{c=$0; gsub("/", "_", c)}{system("echo mv -v " $0 " " c)}'
mv -v /home/pic/Pulpit/kot/1.jpg _home_pic_Pulpit_kot_1.jpg
/bin/sh: Syntax error: word unexpected (expecting ")")
Thank you for your help.
EDIT:
This command works.
find $PWD -name "*.jpg" -exec bash -c 'mv "$0" "${0//\//_}"' {} \;
How to do the same with mawk?
EDIT- 1:
This solution works:
find $PWD -name "*.jpg" | mawk 'a=$0{gsub("/", "_")}{system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")}'
find $PWD -name "*.jpg" | mawk 'a=$0{gsub("/", "_")}{system("mv -v '\''" a "'\'' '\''" $0 "'\'' ")}'
find $PWD -name "*.jpg" | mawk 'a=$0{gsub("/", "_")}{system("mv -v \047" a "\047 \047" $0 "\047 ")}'
Thank you all for your help.
./`[~!($%^_&*){.}\___"`]`1.jpg? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do? – jw013 May 3 '12 at 11:01/is in file name? Like in your output seems./is just added by find. Tryfind . -name "*jpg" -printf "%f\n"instead to output it without./in the begin. – rush May 3 '12 at 11:40/is never a valid character in a file name because it is the path separator. Replacing/in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas./fileis rather ordinary,._fileis a dotfile / hidden file, whereasdir/filebecomesdir_file. Is that really what you intend? – jw013 May 3 '12 at 12:05