Grepping (CVSUP log) files for parts beginning after a certain line - BSD

This is a discussion on Grepping (CVSUP log) files for parts beginning after a certain line - BSD ; A fairly simple AWK script that can be used to "grep" for specific lines that FOLLOW a previous, specific line, comes in handy sometimes. There are bound to be a billion other ways (using multiple commands) to achieve the same ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Grepping (CVSUP log) files for parts beginning after a certain line

  1. Grepping (CVSUP log) files for parts beginning after a certain line

    A fairly simple AWK script that can be used to "grep" for specific lines
    that FOLLOW a previous, specific line, comes in handy sometimes. There are
    bound to be a billion other ways (using multiple commands) to achieve the
    same results, but included below is such a sample script: grepEdit.

    ../grepEdit 'Dec 20'
    FIRSTLINE:[Dec 20]; GREPSTRING:[Edit src]
    Wed Dec 20 01:01:13 CST 2006
    Edit src/sbin/ggate/ggated/ggated.c
    Edit src/sbin/ggate/shared/ggate.c
    Edit src/sbin/ggate/shared/ggate.h
    Edit src/sys/cam/cam_xpt.c
    Edit src/sys/cam/cam_xpt.h
    Edit src/sys/cam/scsi/scsi_da.c
    Edit src/sys/fs/msdosfs/msdosfs_conv.c
    Edit src/sys/gnu/fs/ext2fs/ext2_vfsops.c
    Edit src/usr.bin/nslookup/Makefile
    Edit src/usr.bin/nsupdate/Makefile
    Edit src/usr.sbin/mountd/mountd.c

    ================================================== ====================
    #!/bin/sh
    #
    # grepEdit - 12/14/2006
    #
    # grep lines in a file that contain ,
    # BUT only AFTER a line that begins with
    #
    # This script was originally designed to find certain lines in
    # a Unix cvsup log file (obviously, right?)
    #
    if [ "X$1" = "X" ]; then
    echo "Usage:"
    echo " grepEdit [\
    []]" echo
    echo " Where either/both search strings must be quoted if they contain
    blanks." echo " Optional parameters are indicated by square brackets."
    echo " This script uses a builtin default value for the optional
    parameters." echo
    exit
    fi
    if [ "X$2" = "X" ]; then
    grepstring="Edit src"
    else
    grepstring="$2"
    fi
    if [ "X$3" = "X" ]; then
    grepfile="cvsup.log"
    else
    grepfile="$3"
    fi
    /usr/bin/awk '$0 ~ FIRSTLINE {print "FIRSTLINE:["FIRSTLINE"];\
    GREPSTRING:["GREPSTRING"]";print;while(getline){if(match($0,GREPSTRING))\
    {print $0}}}' FIRSTLINE="$1" GREPSTRING="$grepstring" $grepfile exit

  2. Re: Grepping (CVSUP log) files for parts beginning after a certainline

    User1001 wrote:
    > A fairly simple AWK script that can be used to "grep" for specific lines
    > that FOLLOW a previous, specific line, comes in handy sometimes. There are


    I see.
    Usually I manage with grep -A or grep -B, but I guess this script can be
    handy.
    --
    Torfinn Ingolfsen,
    Norway

  3. Re: Grepping (CVSUP log) files for parts beginning after a certain line

    On Wed, 20 Dec 2006 17:07:05 +0100, Torfinn Ingolfsen wrote:

    > User1001 wrote:
    >> A fairly simple AWK script that can be used to "grep" for specific lines
    >> that FOLLOW a previous, specific line, comes in handy sometimes. There
    >> are

    >
    > I see.
    > Usually I manage with grep -A or grep -B, but I guess this script can be
    > handy.


    The difference with the AWK script is that you don't simply get N lines
    after "context", you only get lines which match "context2" after the line
    that matches "context".


  4. Re: Grepping (CVSUP log) files for parts beginning after a certainline

    User1001 wrote:
    > The difference with the AWK script is that you don't simply get N lines
    > after "context", you only get lines which match "context2" after the line
    > that matches "context".


    Yes, I did understand that. But thank you for explaining. :-)
    --
    Torfinn Ingolfsen,
    Norway

+ Reply to Thread