![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Recursicely search and rename file extension
Greetings to all!!
I have one root folder containing several other folders inside it. This tree structure is deep. And the files are of similar extension. I need to start at the top level and recursively search and rename all the files with say .a extension to .b . This is the code to rename, but then I need to reach out each folder. for i in *.vw ; do mv $i `echo $i | sed 's/vw/view/'` ; done Could anybody help me by providing the outer for loop to traverse all the folders in between? |
|
|||
|
man find or search these forums for examples; there are plenty. You can avoid the sed call, there's a simple substitution operator built into the shell itself. Code:
mv "$i" "${i%.wv}.view"
Also note the use of double quotes. |
|
|||
|
In relation to http://www.unix.com/shell-programmin...-new-post.html just pipe the output of find to sed and trim away everything except the extension.
|
|
|||
|
Quote:
Code:
find . -name "*.mp3" | while read line;
do
mv "$line" .......
done
|
|
|||
|
Hi, Below can list out all the different extension names in the current directory. Hope it can help you a little. Code:
getDel()
{
cd $1
for i in *
do
if [ $i != "*" ]
then
if [ -d $i ]
then
getDel $i
else
ls -l $i
fi
fi
done
cd ..
}
for i in *
do
if [ -d $i ]
then
getDel $i
else
ls -l $i
fi
done > temp
awk '{
if (index($9,".")!=0)
{
t=substr($9,index($9,".")+1,length($9)-index($9,"."))
a[t]=1
}
}
END{
for ( i in a)
print i
}' temp
rm temp
|
|
|||
|
Isn't that a bit excessive, code-wise? Code:
find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -rn |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search pattern in a string and rename | deepakgang | UNIX for Dummies Questions & Answers | 6 | 06-02-2008 02:43 AM |
| Search for all the unique file extension | riverside | Shell Programming and Scripting | 1 | 04-09-2008 05:47 PM |
| File extension search and copy | bsandeep_80 | UNIX for Advanced & Expert Users | 20 | 04-04-2008 11:19 AM |
| How to get file extension | shirleyeow | Shell Programming and Scripting | 17 | 01-17-2008 08:40 AM |
| string search in folders with particular multiple file extension | anikanch | UNIX for Dummies Questions & Answers | 2 | 10-28-2005 11:09 AM |