Results 1 to 3 of 3

Thread: stripping lines from apache log files

  1. #1
    Join Date
    Mar 2006
    Beans
    135
    Distro
    Ubuntu

    stripping lines from apache log files

    Hi,

    i've got a logfile about 50k lines long.

    i'd like to use sed to strip lines containing .jpeg, .gif, .css, images, jpegs, .ico

    so far, i've been entering each command one by one, but i'd like to have a small bash script that'd do it all.

    this is what i've got so far.

    PHP Code:
    sed -'/\.jpg/d' 

    sed -'/\.JPG/d' 

    sed -'/images/d' |

    sed -'/\.css/d' |

    sed -'/\.gif/d' |

    sed -'/\.jpegs/d' |

    sed -'/\.ico/d' |

    sed -'/\.png/d' input.txt output.txt 
    which doesn't work!

    how can i string each of the sed commands together?

    how can i use a variable for input text so i could do something like this?

    PHP Code:
    ./logstripper input.txt 
    thanks for any help!

    takayuki

  2. #2
    Join Date
    Aug 2006
    Location
    Brussels
    Beans
    73
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: stripping lines from apache log files

    Quote Originally Posted by takayuki View Post
    Hi,

    i've got a logfile about 50k lines long.

    i'd like to use sed to strip lines containing .jpeg, .gif, .css, images, jpegs, .ico

    so far, i've been entering each command one by one, but i'd like to have a small bash script that'd do it all.

    this is what i've got so far.

    PHP Code:
    sed -'/\.jpg/d' 

    sed -'/\.JPG/d' 

    sed -'/images/d' |

    sed -'/\.css/d' |

    sed -'/\.gif/d' |

    sed -'/\.jpegs/d' |

    sed -'/\.ico/d' |

    sed -'/\.png/d' input.txt output.txt 
    which doesn't work!

    how can i string each of the sed commands together?

    how can i use a variable for input text so i could do something like this?

    PHP Code:
    ./logstripper input.txt 
    thanks for any help!

    takayuki
    You can either add multiple '-e' command line options to a single sed command, or separate operations inside a single '-e' command with ;
    Code:
    sed -e '/\.gif/d ; /\.css/d ; /\.ico/d'
    Code:
    sed -e '/\.gif/d' -e '/\.css/d' -e '/\.ico/d'
    You can put that sed command in a file, put #!/bin/sh at the top, and add "$@" at the end of your sed script.
    Code:
    #/bin/sh
    sed -e '/\.gif/d ; /\.css/d ; /\.ico/d' "$@"
    But input redirection like you're doing now works just as well.

  3. #3
    Join Date
    Mar 2006
    Beans
    135
    Distro
    Ubuntu

    Re: stripping lines from apache log files

    thanks Woei!

    sed -e '/\.gif/d ; /\.css/d ; /\.ico/d ; /\.JPG/d ; /\.jpg/d ; /.png/d ; /images/d ; /jpegs/d' < "$@" > stripped.txt

    worked great.

    in my previous attempts my syntax was off. i knew i could separate with semicolons, but just didn't have a good example. thanks for the help.

    regards,

    takayuki

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
  •