[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Should be an easy regex/grep question

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






0
paries
Asked:
paries
1 Solution
 
ygouthamCommented:
one dirty way of doing is to

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


0
 
Duncan RoeSoftware DeveloperCommented:
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now