Windows 2003 Shell Scripting
Scripts zur System- und Dateiverwaltung
Reverse - Reihenfolgen umdrehen
Dieses Script dreht die Reihenfolge der Zeilen in einer Textdatei um, das heißt, die letzten Zeilen werden an den Beginn der Datei versetzt und umgekehrt.
Parameter
-
%1 = Datei, deren Inhalt umgedreht werden soll
Code
:: reverse a text file, slow but plain shell
:: test der parameter
if !%1 == ! goto nofile
:: ist die datei auch da?
if not exist %1 goto nofile
:: test auf umgebungsvariable
if not defined temp goto noenv
:: evtl. bestehende datei loeschen
if exist %temp%\tmp.txt del %temp%\tmp.txt
::
for /F "tokens=* usebackq" %%f in (%1) do call :procline
"%%f"
more < %temp%\tmp.txt > %1
del %temp%\tmp.txt
del %temp%\line.txt
goto eof
:procline
echo %~1 > %temp%\line.txt
if exist %temp%\tmp.txt more < %temp%\tmp.txt >> %temp%\
line.txt
more < %temp%\line.txt > %temp%\tmp.txt
goto eof
:noenv
echo Variable TEMP nicht definiert, Abbruch.
goto eof
:nofile
echo Keine Datei angegeben, Abbruch.
goto eof
:notfound
echo Die Datei %1 existiert nicht, Abbruch.
goto eof
:eof