1748227 Members
4437 Online
108759 Solutions
New Discussion юеВ

find help!

 
SOLVED
Go to solution
allanm77
Frequent Advisor

find help!

Hi All!

I have a list of directories

./"002 000 jack"/
./"002 001 black"/
./"002 002 white"/
./"002 003 orange"/

mv "002 000 jack" "`echo "002 000 jack" | awk '{$2 = sprintf("%03d",$2+1); print;}'`"

# the result is:
mv "002 000 jack" "002 001 jack"

I have been struggling to do this through find/xargs combination.

find . -name "002*" -print0 тАж

How can I do this using find/xargs to rename( increment the second sequence by 1).

Thanks,
Allan.

2 REPLIES 2
Dennis Handly
Acclaimed Contributor
Solution

Re: find help! (rename)

>How can I do this using find/xargs to rename (increment the second sequence by 1).

 

Forget about xargs.  Try:

find . -name "002*" -print | awk '

{

save = "\"" $0 "\""

$2 = sprintf("%03d", $2+1)

new = "\"" $0 "\""

print "mv", save, new

}'  |  sh

allanm77
Frequent Advisor

Re: find help! (rename)

Thanks Dennis!