Reputation: 11030
Given file path such as fiz.js
and dir/buz.js
, how to remove suffixes to obtain fiz dir/buz
?
My best shot (I'm looking for something simpler):
find -name '*.js'| \ xargs -I{} echo {} | \ sed 's/.js$//' | \ xargs -I{} mv {}.js {}
Upvotes: 3
Views: 1160
Reputation: 1
find -name '*.js'| xargs -I file rename 's/\.js$//' file
it works and if you want to overwrite existing files you have to add a -f to rename (rename -f).
Upvotes: 0
Reputation: 67301
echo "fiz.js"|awk -F. '{print $1}'
echo "dir/buz.js"|awk -F. '{print $1}'
Upvotes: 0
Reputation: 206851
You could do it with just bash
(version 4) by using globstar
to get a recursive file list.
$ shopt -s globstar
$ for i in **/*.js ; do echo "$i" "${i%.js}" ; done
For the bash man page:
globstar
If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.
${x%ext}
removes ext
from the end of $x
. See String manipulations for more.
Upvotes: 2