Can I flip the order of text with a Windows program?

R

ray

ray wrote:



Your code, didn't fix this. These entries are not in date order.

12/2006 MRI
11/2005 Cured Lupus
02/2006 Stopped Taking drug for Bacteria growth 1st time

This is the same section from my output. Chronological order, ascending
or descending, descending mode selected.

02/2007 Prostrate Biopsy
12/2006 MRI
02/2006 Stopped Taking drug for Bacteria growth 1st time 11/2005
Cured Lupus
06/2005 Chemo for Lupus

All in the spirit of pointless exercises :) Which keeps me busy.

Paul
Date order, shate order. He asked to reverse the file which is exactly
what I did.
 
R

ray

You're very welcome. BTW - I don't know if they still have it, but MS
used to have a free download of 'Unix Tools' somewhere on their website.
I don't know if 'tac' would be included or if it's even there any more.
 
M

Metspitzer

Your code, didn't fix this. These entries are not in date order.

12/2006 MRI
11/2005 Cured Lupus
02/2006 Stopped Taking drug for Bacteria growth 1st time

This is the same section from my output. Chronological order,
ascending or descending, descending mode selected.

02/2007 Prostrate Biopsy
12/2006 MRI
02/2006 Stopped Taking drug for Bacteria growth 1st time
11/2005 Cured Lupus
06/2005 Chemo for Lupus

All in the spirit of pointless exercises :) Which keeps me busy.

Paul
That just goes to show that the code is more complicated than my
list...............and smarter.

Thanks for catching that.
 
V

VanguardLH

Nil said:
That doesn't seem to do what's required here. SORT will order it in
reverse alphanumeric order, but not reverse "arbitrary" order.

I didn't know about this command. I think it's something I'll use!
Well, something would have to be in each line to datestamp that line to
have some "chronological order" involved. So use the /+n parameter to
specify the sort begins at the nth column which would be wherever the
user put the datestamp. Of course, this assumes it isn't just a space-
or tab-delimited record on each line but that the datestamp is at some
fixed column position in each record/line.

It might be possible to us the 'for /f' command in a .bat file where the
"in" parameter uses the specs parameter to parse the lines by a space
character if the datestamp isn't in a fixed columnar position. The
optional "options" parameter is where you specify what delimiter to use
(it's a bit clumsy in syntax to specify the space character so look at
the examples). What I'd do would be to use 'for /f' to parse the lines
by space characters but write a new file with the datestamp as the first
token in each line in the new file. Then I would pipe the new file into
the 'sort' command.

The OP never provided an exhibit of what he was trying to sort so we're
just wasting our time guessing.
 
N

Nil

The OP never provided an exhibit of what he was trying to sort so
we're just wasting our time guessing.
Yes, he eventually did provide a sample of his file. His description of
his list as "chronological" was misleading. The dates were entered
haphazardly, so there was no way to sort it in true date order without
editing the list or using some complex parsing. It was really just an
arbitrary sequence of lines, not suitable for alphanumeric ordering.

He just wanted to reverse the order of lines, not really to sort it by
some criteria. There don't seem to be many utilities to do that
directly. I still think my numbered-column idea is the best solution,
or at least the one I'd use.
 
V

VanguardLH

Nil said:
Yes, he eventually did provide a sample of his file. His description
of his list as "chronological" was misleading. The dates were entered
haphazardly, so there was no way to sort it in true date order
without editing the list or using some complex parsing. It was really
just an arbitrary sequence of lines, not suitable for alphanumeric
ordering.

He just wanted to reverse the order of lines, not really to sort it
by some criteria. There don't seem to be many utilities to do that
directly. I still think my numbered-column idea is the best solution,
or at least the one I'd use.
Okay, now you're reminding of some UNIX command ('head', I think) where
you printed to stdout the first n lines. The 'tail' command printed the
last n lines to stdout (where n = 1). But you'd have to remove the last
1 line from the source file as you prepended it into a new file. Hard
to remember back 12 years ago when was the last time I got stuck having
to do testing on UNIX hosts (AIX, HP-UX, Solaris, SCO, Redhat, SuSE).
Aha, I just Googled on the syntax for 'tail'. You can use the -r
parameter to:

Reverse. Copies lines from the specified starting point in the file in
reverse order. The default for r is to print the entire file in
reverse order.

I doubt the OP wants to install Cygwin to see if it includes the 'tail'
command so he can print (to stdout which can be redirected into a new
file) his source file in reverse order. Alternatively, and instead of
using an emulation layer as does Cygwin to port UNIX commands into
Windows system calls, GNU Utilities for Win32 tries to provide C-coded
programs using the UNIX filenames to do similar functions in
Windows/DOS; see http://sourceforge.net/projects/unxutils/. Doesn't
look to have been updated since 2003. After unzipping, it eats up only
10MB on the hard disk. Alas, like many ports to make a UNIX run native
on Windows, it's not a complete port. I didn't see -r was a support
switch. Maybe Cygwin is more complete. Microsoft had some UNIX for
Windows package but I never looked at it and am not sure about its name.
Microsoft include tail.exe in their Win2003 Resource Kit at
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657.
Never used it so I don't know if it supports the -r switch.

I haven't done any Powershell scripting. Powershell is one of those
non-critical updates that Microsoft pushed via Windows Updates so most
users have it. Since it's a scripting language, maybe you can define a
for-loop to read the nth line of a file to append to an output file
except n would decrement from whatever was the length of the file.
There is a newsgroup at microsoft.public.windows.powershell but it looks
pretty dead. There's also Microsoft's crappy web-based forums, like
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/threads.
 
R

ray

Okay, now you're reminding of some UNIX command ('head', I think) where
you printed to stdout the first n lines. The 'tail' command printed the
last n lines to stdout (where n = 1). But you'd have to remove the last
1 line from the source file as you prepended it into a new file. Hard
to remember back 12 years ago when was the last time I got stuck having
to do testing on UNIX hosts (AIX, HP-UX, Solaris, SCO, Redhat, SuSE).
Aha, I just Googled on the syntax for 'tail'. You can use the -r
parameter to:

Reverse. Copies lines from the specified starting point in the file in
reverse order. The default for r is to print the entire file in
reverse order.

I doubt the OP wants to install Cygwin to see if it includes the 'tail'
command so he can print (to stdout which can be redirected into a new
file) his source file in reverse order. Alternatively, and instead of
using an emulation layer as does Cygwin to port UNIX commands into
Windows system calls, GNU Utilities for Win32 tries to provide C-coded
programs using the UNIX filenames to do similar functions in
Windows/DOS; see http://sourceforge.net/projects/unxutils/. Doesn't
look to have been updated since 2003. After unzipping, it eats up only
10MB on the hard disk. Alas, like many ports to make a UNIX run native
on Windows, it's not a complete port. I didn't see -r was a support
switch. Maybe Cygwin is more complete. Microsoft had some UNIX for
Windows package but I never looked at it and am not sure about its name.
Microsoft include tail.exe in their Win2003 Resource Kit at
http://www.microsoft.com/download/en/details.aspx? displaylang=en&id=17657.
Never used it so I don't know if it supports the -r switch.

I haven't done any Powershell scripting. Powershell is one of those
non-critical updates that Microsoft pushed via Windows Updates so most
users have it. Since it's a scripting language, maybe you can define a
for-loop to read the nth line of a file to append to an output file
except n would decrement from whatever was the length of the file. There
is a newsgroup at microsoft.public.windows.powershell but it looks
pretty dead. There's also Microsoft's crappy web-based forums, like
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/
threads.

Linux has 'tac' which does exactly what he wanted - 'cat' in reverse
order.
 
S

Steve Hayes

The hardest part of what you're trying to do, is getting software
to recognize the dates. Date formats are "hard" things. As humans,
we can instantly spot your 6/22 as Jun.22 and your 3 as March, and
make sense out of it. But a computer, unless the software is pretty
damn fancy, will have trouble digesting those. There are so many
different date formats, it would be difficult to write a routine
that detected all of them successfully. And as a result, when you
go to sort, you're going to find that no matter what you sort with,
there will be errors.
I have a couple of database programs -- askSam and Inmagic -- that claim to be
able to recognise a variety of date formats and to sort accordingly. But the
OP has said he doesn't want 3rd-party software, so that won't help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FireFox order of windows changes after reboot 1
file orderÉÉÉ 1
Sound Recorder in ZorinOS 7 0
Order of searching for device drivers 15
Sound Recorder 30
Problem Steps Recorder 4
SOLVED Add Flip 3D to Context Menu 10
Surprising Flip 1

Top