Page 1 of 1

Spell words in a list backwards

Posted: 23 Oct 2016 07:26
by batchcc
Hello everyone, I am looking for a batch file that can spell all the words in a list backwards and export them to backwards.txt for example:
List.txt

Code: Select all

Word
Cat
Stuff
Batch

Backwards.txt

Code: Select all

Drow
Tac
Ffuts
Hctab

There are ~ 750 words in list.txt

Re: Spell words in a list backwards

Posted: 23 Oct 2016 08:02
by Aacini

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Set the maximum number of letters in the longest word:
set "maxLen=10"

(for /F %%a in (List.txt) do (
   set "word=%%a"
   set "drow="
   for /L %%i in (0,1,%maxLen%) do (
      set "drow=!word:~%%i,1!!drow!"
   )
   echo !drow!
)) > Backwards.txt


Antonio

Re: Spell words in a list backwards

Posted: 23 Oct 2016 10:04
by batchcc
Thanks Aacini, I'm on my phone I'll check it as soon as I can.

Re: Spell words in a list backwards

Posted: 24 Oct 2016 10:54
by aGerman
The flea of jeb's cat jumped across my key board and messed up my script :shock: Only the file names in the first line are left unchanged.

Code: Select all

@sEtlOCal dIsaBlEdElayEdExpaNsION&sEt "<=List.txt"&sEt ">=Backwards.txt"&sEt "]="&sEt "[=0"&sEt "l=Cal"&sEt "I=ExIt"&sEt "\=sEt"&EChO OFF
<:] <Nul (>"%>%" (FOr /F usEBaCkQ^ dElIms^=^ EOl^= %%] IN ("%<%") dO (%\% "/=%%]"&%\%lO%l% ENaBlEdElayEdExpaNsION&%l%l:]&ENdlO%l%)))&%I%/B
%= dIsaBlEdElayEdExpaNsION%IF "!/:~%[%,1!"=="" (EChO(!]!&%I%/B) ElsE (%\% "]=!/:~%[%,1!!]!"&%\%/a "[+=1"&gOtO:])%= ENaBlEdElayEdExpaNsION%


Steffen

PS Have to flee from foxidrive now ...

Re: Spell words in a list backwards

Posted: 24 Oct 2016 14:10
by penpen
My code is not really a solution, but a little funny "cheat" - "just reverse" the "echo line" :twisted: :

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
> "FakedBackwards.txt" <nul set /P "="
>nul chcp 65001
‮ 2>nul & set "rtlo=‮" & (for /F "usebackq delims=" %%a in ("List.txt") do call echo(%%rtlo%%%%a) >> "FakedBackwards.txt"
rem ‭
>nul chcp 850
endlocal
goto :eof
Save it as ANSI even if notepad says something about unicode characters (choose "abort", then "save as": format ANSI).
If the above doesn't work Here is the above batch file in a zip:
FakeBackwards.zip
(355 Bytes) Downloaded 352 times
.

penpen

Re: Spell words in a list backwards

Posted: 24 Oct 2016 15:10
by aGerman
That's funny indeed :lol:
How did you find that RTL byte sequence? Never saw it before.

Steffen

Re: Spell words in a list backwards

Posted: 25 Oct 2016 11:34
by penpen
Last week, i had an issue with an unicode character:
I couldn't access it by using %1-9, although it is contained in %* (just like a comma or space characater).

I then wanted to find out which unicode values (in { U+0000, ..., U+10FFFF } shows the same behaviour.
After that i have listed them in a file and copied the names, and noticed a "weird" line at the character U+202E ('RIGHT-TO-LEFT OVERRIDE').
As soon as i have enough time, i want to test seperator and whitespace characters within other internal commands.


penpen

Re: Spell words in a list backwards

Posted: 25 Oct 2016 12:46
by aGerman
Seems you could do a lot of pranks with it :roll:

Steffen

Re: Spell words in a list backwards

Posted: 25 Oct 2016 15:31
by Aacini
This is funny :D and crazy! :shock:

Code: Select all

@echo off

echo This is normal

‮  2>nul & echo This is funny
rem ‭

echo This is normal

for /F "tokens=2-4" %%a in ("‮ This is crazy! ‭") do echo [%%a %%b %%c]

Output:

Code: Select all

This is normal
This is funny
This is normal
[This is crazy!]

Do not copy the code from above, but from the .zip file.

Antonio

Re: Spell words in a list backwards

Posted: 25 Oct 2016 16:55
by batchcc
Thanks everyone I've only tried the first solution but I'll certainly try the others as soon as I can :D

Re: Spell words in a list backwards

Posted: 27 Oct 2016 15:57
by Aacini
Try the "test-tab.html" Batch file. Get it from the .zip file and extract it using the standard Windows extractor, not any 7zip third-party extractor.

Image

Antonio

Re: Spell words in a list backwards

Posted: 28 Oct 2016 09:39
by dbenham
JREPL.BAT with a bit of user supplied JScript works well:

Code: Select all

jrepl "^.+" "$txt=$0.split('').reverse().join('')" /jq /f List.txt /o Backwards.txt

A bit more code is required if you want the result to have the first letter uppercase, and the rest lowercase.

Code: Select all

jrepl "^.+" "$txt=$0.split('').reverse().join('');$txt=$txt.charAt(0).toUpperCase()+$txt.slice(1).toLowerCase()" /jq /f List.txt /o Backwards.txt


Dave Benham

Re: Spell words in a list backwards

Posted: 28 Oct 2016 12:51
by Squashman

Code: Select all

@echo off
set "sentence=This is Crazy & Stupid!!!"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
set /A n=0
setlocal enabledelayedexpansion
:label
set /A n+=1
set /p ".=_!BS!!Sentence:~-%n%,1!"<nul
IF NOT "!Sentence:~%n%!"=="" GOTO label
echo.
endlocal
pause


Without Delayed Expansion.

Code: Select all

@echo off
set "sentence=This is Crazy & Stupid!!!"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
set /A n=0
:label
set /A n+=1
CALL set /p ".=_%BS%%%Sentence:~-%n%,1%%"<nul
CALL SET "S=%%Sentence:~%n%%%"
IF NOT "%S%"=="" GOTO label
echo.
pause