Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
batchcc
- Posts: 139
- Joined: 17 Aug 2015 06:05
-
Contact:
#1
Post
by batchcc » 23 Oct 2016 07:26
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
Backwards.txt
There are ~ 750 words in list.txt
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#2
Post
by Aacini » 23 Oct 2016 08:02
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
-
batchcc
- Posts: 139
- Joined: 17 Aug 2015 06:05
-
Contact:
#3
Post
by batchcc » 23 Oct 2016 10:04
Thanks Aacini, I'm on my phone I'll check it as soon as I can.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 24 Oct 2016 10:54
The flea of jeb's cat jumped across my key board and messed up my script
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 ...
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#5
Post
by penpen » 24 Oct 2016 14:10
My code is not really a solution, but a little funny "cheat" - "just reverse" the "echo line"
:
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:
.
penpen
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#6
Post
by aGerman » 24 Oct 2016 15:10
That's funny indeed
How did you find that RTL byte sequence? Never saw it before.
Steffen
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#7
Post
by penpen » 25 Oct 2016 11:34
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
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 25 Oct 2016 12:46
Seems you could do a lot of pranks with it
Steffen
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#9
Post
by Aacini » 25 Oct 2016 15:31
This is funny
and crazy!
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
-
Attachments
-
- test.zip
- (231 Bytes) Downloaded 423 times
-
batchcc
- Posts: 139
- Joined: 17 Aug 2015 06:05
-
Contact:
#10
Post
by batchcc » 25 Oct 2016 16:55
Thanks everyone I've only tried the first solution but I'll certainly try the others as soon as I can
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#11
Post
by Aacini » 27 Oct 2016 15:57
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.
Antonio
-
Attachments
-
- test.zip
- (168 Bytes) Downloaded 474 times
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#12
Post
by dbenham » 28 Oct 2016 09:39
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
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#13
Post
by Squashman » 28 Oct 2016 12:51
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