|> >I have a straight ascii file. Each entry is separated by a blank line.
|> >Each entry consists of more than one line.
|> >I need some code that will perform an alphabetical sort of the entries.
|> >Any type of code will do, but some kind of awk or sed script would be
|> >convenient.
|> >Any ftp site suggestions?
|> >[The application is sorting a bibliography for input into latex, without having
|> >to use bibtex -- has anyone else experienced this problem?]
|> If I understand what you're saying correctly - I suggest the easiest method is
|> to combine all the multiline entries into one line, seperating them with say
|> " ~ " or some other unique character surrounded by a space. At the same time
|> removing the blank lines. Sort as usual then convert " ~ " back to newline.
|> The first part should be a trivial awk script.
It is. I'm surprised not to see others suggesting this, as it is a
classical example of a small AWK feature (see page 84 in "The AWK
Programming Language"):
#! /bin/sh
awk '
BEGIN { RS = "" ; FS = "\n" }
{
printf( "%s" , $1 )
for ( i = 2 ; i <= NF ; i ++ )
printf( "$%s" , $i )
printf "\n"
}
' |
sort |
awk '
BEGIN { FS = "$" }
{
for ( i = 1 ; i <= NF ; i ++ )
print $i
print
} '
This sorts on the first field, but it is easy to add any particular
field you like to the start of the line in the first pass through AWK,
then simply not output it in the second. (This is what actually happens
in the example in the book.)
--
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
--Beratung in industrieller Datenverarbeitung