0

I've been experiencing a wee issue in attempting to rename a batch of files. I need to insert (retrospectively) hyphens between a string of words in a group of unrelated files. I thought i would employ sed to replace the white spaces with hyphens and I arrived at this (please see below). Now this returns the correct result on the command-line, but, doesn't physically change the file name in the directory.

$ ls 'long long long filename.txt' | sed 's/\s/-/g'    

output

long-long-long-filename.txt

Any help or suggestion would be much appreciated.

npr60
  • 81
  • 8
  • 2
    `for f in *.txt; do mv "$f" "${f//[[:space:]]/-}"; done` – Wiktor Stribiżew Aug 21 '20 at 16:11
  • 1
    You have to actually issue a command that changes the filename; you're listing the filenames and then modify strings. It's either `mv`, like in the comment above, or one of two flavours of the `rename` command, as in the linked question. – Benjamin W. Aug 21 '20 at 16:15

0 Answers0