Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - Sort Records by first field in each record 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I was wondering how to sort a group of records alphabetically by the first field in each record.

So I have a group like this:

Client: orange
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 08:17:06 (1158934626)

Client: apple
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 09:17:03 (1158938223)

Client: grape
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 08:22:06 (1158934926)

and I want the end result to look like this:

Client: apple
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 09:17:03 (1158938223)

Client: grape
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 08:22:06 (1158934926)

Client: orange
Sched Label: audit_arch_1yr
Backup Time: Fri Sep 22 2006 08:17:06 (1158934626)


any help would be much appreciated.
 
Hi

Ugly. Very ugly.
Code:
awk 'BEGIN{RS="\n *\n"}{gsub(/\n/,"\a")}'1 [green][i]/input/file[/i][/green] | \
sort | \
awk '{$0=$0"\n";gsub(/\a/,"\n")}1'
Tested with [tt]gawk[/tt].

Feherke.
 
Hmm... this is the output I got from the previous suggestion:

--paste--

Backup Time: Fri Sep 22 2006 08:17:06 (1158934626)

Backup Time: Fri Sep 22 2006 08:22:06 (1158934926)

Backup Time: Fri Sep 22 2006 09:17:03 (1158938223)

Client: apple

Client: grape

Client: orange

Sched Label: audit_arch_1yr

Sched Label: audit_arch_1yr

Sched Label: audit_arch_1yr

--end paste--

Any other ideas?
 
Hi

Seting a regular expresion as [tt]RS[/tt] could be a problem for your [tt]awk[/tt].

Maybe an off-topic answer will help :
Code:
perl -ne '$s.=$_;END{print join "\n\n",sort split /\n *\n/,$s}' < /input/file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top