Should be an easy regex/grep question

Posted on 2007-07-30
Last Modified: 2010-04-20
this should be an easy regex/grep question.
i have an gzip sql file that has entries like:
INSERT INTO `newsletter` VALUES (50,'mydir',0,0,'white','','','','',0,1);
there are bunch of entries in this file and the 50 is an id.
There are also lots of other tables in this file as well.
I tried this but my regex skills sucks:
#gunzip --stdout mysql.7-30-2007.dmp.gz | grep -i "INSERT INTO \`newsletter\` VALUES (*,\'mydir\',"
the above line fails
but this works(but does not do anything for me, cause i need that mydir)
#gunzip --stdout mysql.7-30-2007.dmp.gz | grep -i "INSERT INTO \`newsletter\` VALUES "

so what i am trying to do is find everything with "INSERT INTO `newsletter` VALUES (50,'mydir'", but the 50 can be anything.

thanks for any help

Question by:paries
    LVL 14

    Expert Comment

    one dirty way of doing is to

    gunzip --stdout mysql.7-30-2007.dmp.gz | grep -i "INSERT INTO \`newsletter\` VALUES " | grep "mydir"

    LVL 34

    Accepted Solution

    cat  mysql.7-30-2007.dmp.gz|gunzip|egrep "INSERT INTO \`newsletter\` VALUES \(.*,'mydir',"
    Inside double-quotes, the backtick is special to shell and must be escaped. shell (bash) removes the backslashes.
    Inside a regular expression, parentheses are special and must be escaped if you want to match against them. My bash does *not* strib the backslash from '\(" - that surprised me but anyway...
    If in doubt how the shell expands something, "set -x" will show you what's happening

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now