in reply to Re: need to extract top and bottom lines...
in thread need to extract top and bottom lines...

saberworks,
Sometimes it's pointless to use perl.

This is very true. There are plenty of command line utilities and variants that were designed for a very specific task that they do very well. Not an exhaustive list, but I am quite fond of:

The last one is what I wanted to comment on. Not all greps support -B. It is a GNU invention. HPUX and Solaris (at least up to 8), for instance, do not ship with it. When I have to work to make one of these do what I want, I tend to revert back to Perl.

Cheers - L~R

  • Comment on Re^2: need to extract top and bottom lines...

Replies are listed 'Best First'.
Re^3: need to extract top and bottom lines...
by Errto (Vicar) on Dec 15, 2004 at 05:25 UTC
    I encounter this problem very frequently on Solaris. My solution is just to install the GNU tools and modify my $PATH accordingly. http://www.sunfreeware.com is a real beaut. If you have a Solaris box without sufficient privileges to do this or an agreeable sysadmin, you have my sympathy.
Re^3: need to extract top and bottom lines...
by superfrink (Curate) on Dec 15, 2004 at 05:47 UTC
    I also use "sed" quite often and "awk" is nice if you want to grab columns out of a file. Just last week someone told me the letters in awk stand for the names of the developers (Aho, Weinberger, Kernighan).

    I actually have command lines about two lines long that I use to work out things like for example which IP addresses are connected to my machine's SMTP port sorted by number of connections. I just haven't gotten around to writting a script or setting up a shell alias to do it yet.

    I played with a perl shell once but it didn't feel right (ie I wasn't used to it yet, years of BASH have me in their grasp). Also the control characters (^U, ^A, ^E, etc) didn't work on the main server I use at work (but did on my desktop). I don't remember the shell name but I think it supported commands something like " ls -1 | s/aaa/bbb/g " and more.
Re^3: need to extract top and bottom lines...
by DrHyde (Prior) on Dec 15, 2004 at 11:14 UTC
    In that case I'd use awk to solve this problem.