sorting and reversing lines of a file
Tony L. Hansen
hansen at pegasus.ATT.COM
Sat Feb 11 12:12:50 AEST 1989
>>(1) reverse the order of lines in a file
>> but leave the lines themselves intact.
>> The Unix utility does just the opposite of this.
This sounds like a job for "tac" which has been posted at least a couple of
times to the net. Here's the man page.
NAME
tac - concatenate and print files in reverse
SYNOPSIS
tac file ...
DESCRIPTION
Tac reads each file in sequence and writes it on the standard
output with the lines in reverse order. Thus:
tac file
prints the file in reverse, and:
tac file1 file2 >file3
concatenates the first two files, reversed, and places the result
on the third.
tac file | tac
will reproduce the contents of the file. If no input file is given,
or if the argument - is encountered, tac reads from the standard
input.
WARNING
Command formats such as
tac file1 file2 >file1
will cause the original data in file1 to be lost, therefore, take
care when using shell special characters.
SEE ALSO
cat(1).
Tony Hansen
att!pegasus!hansen, attmail!tony
More information about the Comp.unix.questions
mailing list