need help grep'g

Posted on 2006-04-14
Last Modified: 2010-04-20
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
Question by:paries
    LVL 12

    Expert Comment


    grep -w ssmith dump.sql

    maybe grep -iw if you need case insensitivity
    LVL 9

    Accepted Solution

    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 :)
    LVL 9

    Expert Comment

    Heem14, you beat me by one minute!
    LVL 12

    Expert Comment


    you don't even need the quotes - because the single quote is considered a word breaker.
    LVL 22

    Expert Comment

    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.

    LVL 12

    Expert Comment

    thanks, I appreciate the points.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
    Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    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…

    737 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

    17 Experts available now in Live!

    Get 1:1 Help Now