| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Env: German Win8.1x64 with sed v407 from UnxUtils.
I want to queries full filepathes and finds any filename (+extension)
containing umlauts and some special characters. Goal is to do some
substitutions for the filenames only and to redirect results into a new
file.
This is what I have so far (working):
Command to get a list of filenames that contain umlauts and some special
chars (piping the DIR command):
DIR /B /S /A:-D "E:\"|sed --text -n
"s/^\(.*\\\)\(.*[äüößÄÜÖß&\d183]\+[^\\]\+\)$/\1\2/p" >> OutFile1
The resulting file should:
1. contain a renaming command (REN+space) at start of each line in OutFile1.
2. contain the filename of the filepath only at end of each line.
Example: REN "e:\XYZ\XY\2011 - Schürer _Low Back Pain.pdf"
"2011-Schuerer_Low Back Pain.pdf"
This is my loop command in which substitutions are made to the original
file. Output is redirected to a new file:
FOR /F "tokens=1* delims= " %%a IN (OutFile1) DO (
FOR /F "tokens=1* delims= " %%A IN ('ECHO "%%a"^|sed --text
"s/Ä/Ae/g;s/ä/ae/g;s/Ü/Ue/g;s/ü/ue/g;s/Ö/Oe/g;s/ö/oe/g;s/ß/ss/g;s/&/+/g;s/\d183/-/g;s/[[:space:]]*\([-+_.]\)\{1,\}[[:space:]]*/\1/g;s/\([-+_.]\)\{2,\}/\1/g;s/[[:space:]]\{2,\}/
/g"') DO (ECHO REN "%%a" "%%~nxA" >> %2)
)
%%~nxA prints only the filename(n)+extension(x) of the full path(A).
This code is increddible slow for long files (as always for loops).
Questions:
1. I'm sure it must be possible to solve this task with sed only without
using a FOR loop. I'm runnig out of ideas here.
2. What about the used sed commands? In need of being improved? Or are
they even faulty?
3. Another one; is sed able to count and print characters for each line
of a file (similar to wc)?
Thanks much in advance for any reply
Zharif