Fabiuz99 Fabiuz99 - 5 months ago 19
Linux Question

Link separated words

I would know if there is a program or a script that can link separated words in a file name with a dot (or other punctuation marks).
Example:
How are you.pdf >>> How.are.you.pdf

I did not explain myself well, I'm looking for a bash script that can rename file names

Answer

Assuming you have How are you.pdf in a variable you can use parameter expansions:

% a="How are you.pdf"
% echo "${a// /.}"
How.are.you.pdf

The above is a bash expansion and doesn't work in a POSIX shell. In that case sed or simulare would be needed.

To rename all files in the current directory:

for a in *; do
  [ -f "$a" ] || continue
  mv -- "$a" "${a// /.}"
done
Comments