Re: General UNIX puzzle

From: Bill Campbell (freebsd_at_celestial.com)
Date: 01/17/04

  • Next message: ar: "install FreeBSD using PPPoE"
    Date: Sat, 17 Jan 2004 14:04:00 -0800
    To: Eric Anderson <freebsd@binprod.com>, questions@freebsd.org
    
    

    On Sat, Jan 17, 2004, Brett Glass wrote:
    >At 02:44 PM 1/17/2004, Eric Anderson wrote:
    >
    >>You should do your own Comp Sci homework. This looks like (especially considering the time of th year) the begining of a Unix Basics course.
    >
    >Nope; I'm quite experienced with UNIX. However, I posted the
    >question because I wanted to see what the most efficient
    >and clever answers would be. For example, while I received
    >answers involving languages, such as sed and awk, the simplest
    >answer to at least one of them seems to use grep.

    All of those (sed, awk, grep) involve making a copy of the original file
    which can cause problems with ownership, permissions, concurrent access,
    etc. The gnu shtool is one of the most useful tools for this for in-place
    updates that's considerably more friendly than the ``ed'' examples I posted
    (truncated by my mailer for some reason). One can use multiple sed
    commands in one step:

    shtool subst [-s] \
            -e '99d' \
            -e '/pattern1/s/$/\ninsert line after line with pattern1/' \
            -e '/pattern2/s/^/\ninsert line before pattern 2/' \
            -e '/pattern3/s/pat1/pat2/g' \
            file1 [file2, ....]

    The -s option preserves the timestamps of the file(s) edited.

    Remember if doing things based on line numbers (a) to make these changes
    first from highest line number to lowest to prevent confusion.

    The two lines with pattern1 and pattern2 require sed that recognizes the \n
    escape sequence (gnu-sed does, FreeBSD doesn't).

    Bill

    --
    INTERNET:   bill@Celestial.COM  Bill Campbell; Celestial Software LLC
    UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
    FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
    URL: http://www.celestial.com/
    A Galileo could no more be elected president of the United States than
    he could be elected Pope of Rome.  Both high posts are reserved for men
    favored by God with an extraordinary genius for swathing the bitter
    facts of life in bandages of self-illusion.
                    -- H. L. Mencken
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    

  • Next message: ar: "install FreeBSD using PPPoE"

    Relevant Pages

    • Re: ssh and chroot
      ... ++ echo /bin/mkdir ... ++ awk '' ... ++ grep '^/' ...
      (comp.security.ssh)
    • Re: The smartest band in the world?
      ... I mainly use grep, but I'm ... going to learn awk and sed and improve my bash scripting. ... Oracle accreditation coure, well in the grad courses at least, everything ...
      (alt.guitar)
    • Re: I need a custom script to extract data from my web logs.
      ... >> You aren't passing anything to awk and you don't need awk anyway. ... My original script was using awk to output the data by ... > piping the output of the original grep through awk to the printf. ... (i.e. searchlogs log???? ...
      (comp.unix.shell)
    • Re: grep switches
      ... grep -n 'pattern' file /dev/null ... grep, so all I need is to the file names and line numbers of the text ... awk '/pattern/ ... But there are some unwanted error ...
      (comp.unix.shell)
    • Re: The smartest band in the world?
      ... I mainly use grep, but I'm going to learn awk and sed and improve my bash scripting. ... mostly taching Oracle and at the subjects completion you can do the Oracle accreditation coure, well in the grad courses at least, everything seems to have a proprietry product focus. ...
      (alt.guitar)