I have to write a script to rename the every last sub-directory in a directory structure if the last sub-directory name doesn't contain "submitted".
eg:
given directory path:/u01/home/somedir
somedir can have many subdirectories and each subdirectory inturn has many subdirectories.
somedir
|-A/B/C
|-D/E
|-F/G/a.txt
i need to rename the directories C to "C-Submitted",E to "E-Submitted",
G to "G-Submitted" etc;
Pls. provide some pointers.
Thanks in advance.
find /u01/home/somedir -type d |
while read dir
do
echo "$dir" | grep -q 'somedir$' && continue
mv $dir ${dir}-Submitted
done
one way to do this.
Try this...
#!/bin/bash
for line in $(find test -type d)
do
z=$(echo $line | grep "$str" )
if [[ -z "$z" && $(echo $str | grep -v "Submitted") ]]
then
echo "mv $str $str-Submitted"
#mv $str $str-Submitted
fi
str=$line
done
if [ $(echo $line | grep -v "Submitted") ]
then
echo "mv $str $str-Submitted"
#mv $str $str-Submitted
fi
If the above code is printing the correct "mv" commands, then un-comment the "mv" statements, remove the "echo" statements and execute the script again.
echo "mv $str $str-Submitted"
#mv $str $str-Submitted
# should be changed to
mv $str $str-Submitted
--ahamed
Thanks guys!! They are working like a charm.Thanks again