In the example that follows, the pattern is separated by - and the length is 3. My question is: Is there a more efficient way to do this?         $ echo $foo./abcd-123-efghij-45678.pdf$ echo $foo | sed -E 's:([^-\.\/]{3})([^-]*):\1:g'| sed s/$/.${foo##*.}/./abc-123-efg-456.pdf$ foo=${foo%.pdf}.djvu$ echo $foo./abcd-123-efghij-45678.djvu$ echo $foo | sed -E 's:([^-\.\/]{3})([^-]*):\1:g'| sed s/$/.${foo##*.}/./abc-123-efg-456.djvuWhat I ultimately need this command for, is to replace ... by it inside for f in $(find . -name pattern); do mv $f $(...);done
Trim substrings of a filename, each matching a pattern to a given length
text processing;sed
You could shorten that toecho ./abcd-123-efghij-45678.pdf | sed -E 's:([^-\.\/]{3})([^-]*):\1:g; s/$/.djvu/'but otherwise, it's pretty much the best you can do with sed.