The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Previous Message  |  Next Message 
 Re: Searching the ports
Author: Benjamin Lutz 
Date:   09-04-02 02:48

Here's a small perl hack I created for doing just that, searching through the INDEX file.

Works like this: if you call it like this "./" it'll just output the whole index in a reformated, more easily readable way, or you do "./ net" to only display stuff in the "net" category.
Now, to actually make use of it I suggest just piping it into grep or something like that. I've saved the output as "index", so to search for lynx I'd do a "grep lynx index".


# Copyright 2001 Benjamin Lutz
# - written on 2001-09-25
# parses /usr/ports/INDEX and prints the name and description of each
# entry in a category. You may specify that category as commandline
# parameter.

use strict;

open FILE, "/usr/ports/INDEX";

my @line;

while ($_ = <FILE>) {
my @thisline = split /\|/, $_;

$thisline[1] =~ s/\/usr\/ports\/(.*)/$1/;
$thisline[0] =~ s/(.*)-(.*)/$1/;

push @line, { name => $thisline[0],
version => $2,
description => $thisline[3],
category => $thisline[6],
path => $thisline[1] };

close FILE;

my $thisline;
my %categories;

foreach $thisline (@line) {
my $category;

foreach $category (split /\s/, $thisline->{category}) {
$categories{$category} = 1;
my $input;

if (@ARGV) {
$input = $ARGV[0];
#} else {
# print "Enter a category: ";
# $input = <STDIN>;
# chomp $input;

my @output;

foreach $thisline (@line) {
next unless (not $input or
$thisline->{category} =~ m/^$input$/i or
$thisline->{category} =~ m/^$input\s/i or
$thisline->{category} =~ m/\s$input$/i or
$thisline->{category} =~ m/\s$input\s/i);

push @output, sprintf "%-15s %-15s %s\n", $thisline->{name}, $thisline->{path}, $thisline->{description};

@output = sort {$a cmp $b} @output;

print @output;

 Reply To This Message  |  Forum List  |  Flat View   Newer Topic  |  Older Topic 

 Topics Author  Date
 Searching the ports   new
William Cooper 21-02-02 14:06 
 Re: Searching the ports   new
parv 22-02-02 10:34 
 Re: Searching the ports   new
Benjamin Lutz 09-04-02 02:48 
 Re: Searching the ports   new
parv 15-04-02 07:00 
 Re: Searching the ports   new
parv 15-04-02 07:05 
 Re: Searching the ports   new
el_kab0ng 19-09-05 18:09 
 Re: Searching the ports   new
Dan 19-09-05 18:31 
 Re: Searching the ports   new
el_kab0ng 19-09-05 18:38 
 Re: Searching the ports   new
parv 19-09-05 23:09 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum