• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

need help grep'g

wow this is embarrasing

i have an sql file that is monsterous.

i need to getout all the sql statements that have 'ssmith' , This includes those surrounding single qoutes. there are many smiths and words with smith in them.

I tried

grep ''ssmith'' dump.sql (thats two single qoutes)
grep "'ssmith'" dump.sql
grep "\'ssmith\'" dump.sql (finds nothing)

they all still find stuff like melissasimmonssmith

please help
0
paries
Asked:
paries
  • 3
  • 2
1 Solution
 
Heem14Commented:
try

grep -w ssmith dump.sql

maybe grep -iw if you need case insensitivity
0
 
sda100Commented:
Hi paries

grep -w "'ssmith'" dump.sql

... is the one you need (double-quotes surrounding single-quotes).  The -w is to match at word boundaries.

Steve :)
0
 
sda100Commented:
Heem14, you beat me by one minute!
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
Heem14Commented:
:)

you don't even need the quotes - because the single quote is considered a word breaker.
0
 
pjedmondCommented:
Another approach is to:

cat dump.sql | grep -e "[ ']ssmith[ ']" > output.txt

Using > to send to the output file,
or >> to append to the output file.

The above statment breaks down your requirement really easily. First cat the file concerned ,then get lines that have either a space or ' followed by ssmith and then followed by either a space or '. Obviously you can:

grep -e "[ ']ssmith[ ']" dump.sql

But looking at the structure of the above command it is easier to understand and manage, without having to resort to:

man grep

Also the above structure is more versatile for other scenarios that you might encounter.

HTH:)
0
 
Heem14Commented:
thanks, I appreciate the points.

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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