hogg said:
I was wondering if there was a one liner that would reverse order a
file w/o having to write the output to another file. I can reverse
order a file using: awk '{printf "%10d\t%s\n",NR,$0}' <FILE> | sort -nr
| cut -f2- >> <FILE2>,
No need for all of that, at least not on modern Linux:
tac FILE > FILE2
but this makes me create another file. I wanted
to be able to do it 'on the fly'.
It does not make you create another file, that is what you chose to
do. You could certainly pipe the output into just about anything you want,
rather than redirecting it to a file.
You were so busy telling us what you didn't want to do, you failed to tell
us what you do want to do.
If you want the reversed data as input to perl, you can do:
open my $fh, "tac File |" or die $!;
while (<$fh>) {
#do whatever
}
close $fh or die $!;
If you want the reversed data written back to the same file, you could tie
the file to an array with Tie::File, and then just reverse the array. But
that would probably be ungodly slow. You could study Tie::File code and
then make your own module which does what you want quickly, and then invoke
that module with a one-liner. Come to think of it, you could just read the
file into an array, reverse the array, and print it back out, assuming the
whole file fit into memory. Leaving perl and going back to Linux, you
could do (in tcsh, doesn't seem to work in bash):
tac FILE | ( rm FILE ; cat - > FILE )
Xho