Results 1 to 6 of 6

Thread: [SOLVED] sed and regex help

  1. #1
    Join Date
    Dec 2005
    Location
    Australia
    Beans
    45
    Distro
    Ubuntu 9.10 Karmic Koala

    [SOLVED] sed and regex help

    I noticed the other day that my /var/log/apache2 folder was filling up with heaps and heaps of logs (>1500)

    I am not going to stop logging, so please don't offer that as an answer

    All of my log files are well named (in my mind) eg:

    site1-error.log
    site1-error.log.0
    site1-error.log.1.tgz

    site1-access.log
    site1-access.log.0
    site1-access.log.1.tgz

    site2-error.log
    site2-error.log.0
    site2-error.log.1.tgz

    site2-access.log
    site2-access.log.0
    site2-access.log.1.tgz

    etc

    So what I wanted to do was to break them into smaller chunks, based on sitename:

    /var/log/apache2/site1/error.log
    /var/log/apache2/site1/access.log
    /var/log/apache2/site2/error.log
    /var/log/apache2/site2/access.log

    etc

    This requires editing a lot of /etc/apache2/sites-available files...

    sed '/ErrorLog/ s/\/.*-error.log/&\/error.log/g' bashtest.txt

    almost works but gives me:

    ErrorLog /var/log/apache2/webalizer-error.log/error.log
    ErrorLog /var/log/apache2/wiki-error.log/error.log

    instead of the desired

    ErrorLog /var/log/apache2/webalizer/error.log
    ErrorLog /var/log/apache2/wiki/error.log

    I have tried replacing the & with \1 (as I read somewhere), $1 (common in this regard), $0, $@ but none seems to work?

    Any ideas? Am I even using the right language? should I be using perl?

  2. #2
    Join Date
    Dec 2005
    Location
    Australia
    Beans
    45
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sed and regex help

    Actually, I am aware of the problem with perl:

    s/\/.*-error.log/&\/error.log/g'

    willl match the whole line (greedy) not just that one little bit....

  3. #3
    Join Date
    Sep 2006
    Beans
    2,914

  4. #4
    Join Date
    Dec 2005
    Location
    Australia
    Beans
    45
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sed and regex help

    it's just a list of parts of my vhosts files:

    ErrorLog /var/log/apache2/site1-error.log
    Errorlog /var/log/apache2/site2-error.log
    ErrorLog /var/log/apache2/site3-error.log

    CustomLog /var/log/apache2/site1-access.log combined
    CustomLog /var/log/apache2/site2-access.log combined
    CustomLog /var/log/apache2/site3-access.log combined

    I was just using it for testing, later, I do the wrapping script

    for $i in *
    <change text in $i>

    then I apply the script to my /etc/apache2/sites-available folder

  5. #5
    Join Date
    Sep 2006
    Beans
    2,914

    Re: sed and regex help

    Quote Originally Posted by datakid View Post
    sed '/ErrorLog/ s/\/.*-error.log/&\/error.log/g' bashtest.txt

    almost works but gives me:

    ErrorLog /var/log/apache2/webalizer-error.log/error.log
    ErrorLog /var/log/apache2/wiki-error.log/error.log

    instead of the desired

    ErrorLog /var/log/apache2/webalizer/error.log
    ErrorLog /var/log/apache2/wiki/error.log
    I am still not sure what you wish to do, but anyhow, i will just assume you want this
    Code:
    ErrorLog /var/log/apache2/webalizer-error.log/error.log
    to become this
    Code:
    ErrorLog /var/log/apache2/webalizer/error.log
    You could just substitute -error.log with blank
    Code:
    # sed 's/-error.log//' file
    ErrorLog /var/log/apache2/webalizer/error.log
    ErrorLog /var/log/apache2/wiki/error.log

  6. #6
    Join Date
    Dec 2005
    Location
    Australia
    Beans
    45
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: sed and regex help

    of course - thanks for the help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •