batch to reverse my output file

I had this question after viewing batch findtext match 2 criteria.
simple question can i reverse the output so the 1st line is last

My output file looks like
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      4          DSA-3234 XXXXXXXXXX
02/01/18 10:14:16 ( 0) Panic Alarm     2          DS-3382 WUBBLU, DO

i would like it to look like
02/01/18 10:14:16 ( 0) Panic Alarm     2          DS-3382 WUBBLU, DO
02/01/18 10:12:38 ( 0) Fire Alarm      4          DSA-3234 XXXXXXXXXX
02/01/18 10:12:38 ( 0) Fire Alarm      2          DS-3682 XXXXXXXXXX
02/01/18 10:11:55 ( 0) Fire Alarm      3          DS-5382 XXXXXXXXXX
LVL 1
csePixelatedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
You can try sorting it, using the /R option for reverse order.  Assuming that's what you are after.  But keep in mind that will be a simple sort, of the date as you have it and time, so when the month changes from 12 to 01 in the middle of the data (if it does) then it could break down.

If you really need a chronological sort (or reverse chronological) then your records would need to start with something like YYYYMMDDhhmmss or YYYY/MM/DD hh:mm:ss, where a text sort of that data would result in the proper ordering.

See SORT /? for info on the sort command.


»bp
0
NVITEnd-user supportCommented:
If you want it to work without sorting, i.e. keep the true reversed order, you can use this vbscript method:
This is especially faster with big text files.

Save the code to a filename Backwards.vbs

' Read a Text File from the Bottom Up

Dim arrFileLines()
fname = WScript.Arguments.Item(0)
i = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(fname, 1)

Do Until objFile.AtEndOfStream
     Redim Preserve arrFileLines(i)
     arrFileLines(i) = objFile.ReadLine
     i = i + 1
Loop

objFile.Close

For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
    Wscript.Echo arrFileLines(l)
Next

Open in new window


Run it in a CMD window with an original filename big.txt. Output results to big_reversed.txt
cscript //nologo Backwards.vbs big.txt>big_reversed.txt

Open in new window

0
Bill PrewCommented:
You can do that same basic thing in DOS commands if what you want is just to reverse the order of the lines.  Something like:

(for /f "tokens=1* delims=]" %%A in ('find /v "" /n^<input.txt^|sort /r') do echo %%B)>output.txt

Open in new window

Reads from input.txt, reverses the order of the lines, and writes to output.txt.


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.