How to fix a bunch of files with a space between the basename + extension e.g. file .pdf
#1589
Unanswered
luckman212
asked this question in
Q&A
Replies: 1 comment
-
Scratched my own itch for now with a shell script #!/usr/bin/env bash
if [[ -z $1 ]]; then
cat <<-EOF
helper script to fix spaced at the end of filenames between the name + extension
see: https://github.com/sharkdp/fd/discussions/1589
usage: fd ' \.pdf' -x extfix.sh {}
EOF
exit 0
fi
input=$*
basename=$(basename "$input")
dirname=$(dirname "$input")
ext=${basename##*.}
fname_noext=${basename%."$ext"}
fname_trimmed=${fname_noext%% }
final=$dirname/$fname_trimmed.$ext
cat <<EOF
input= [$input]
dirname= [$dirname]
basename= [$basename]
ext= [$ext]
fname_noext= [$fname_noext]
fname_trimmed= [$fname_trimmed]
final= [$final]
EOF
[[ -e $input ]] || exit
[[ -e $final ]] && exit
mv -v "$input" "$final" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was wondering if anyone has a sweet one-liner for scanning over a directory for any files that have a space between the basename and the extension, for example
I inherited a bunch of these and want to clean them up.
I got as far as finding them with
But I wanted to pass an
-x mv {...} {...}
using placeholders and there doesn't seem to be a way to "grab" just the extension?Beta Was this translation helpful? Give feedback.
All reactions