Results 1 to 10 of 10

Thread: Quick egrep problem

  1. #1
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Quick egrep problem

    Morning. Am trying to run egrep using a file for multiple search string input - the folder I'm searching is a Windows share I've mounted and can browse fine.
    I'm (trying to) redirect the output from egrep to a file but am not having so much luck although it is being displayed on the console.....
    For example:

    Code:
    egrep -f ~/strings.txt -r /media/windows-share/  >> ~/log.txt
    The search returns the following type of thing:

    Code:
    /media/windows-share/subfolder/subsubfoler/file.doc: No such file or directory
    I am seeing the log.txt file get created but never have the file names in which the search terms are found appended to it...can anyone help?

  2. #2
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Re: Quick egrep problem

    Actually I think I might have found what's actually happening here.
    The output redirection is working for most matches it finds - just not for some specific files though.

    At first glance it seems like it's an issue with special characters. For example one had a "-" in the file name. Has anyone else seen the same behaviour?

  3. #3
    The late but legendary peterb - Onward and Upward peterb's Avatar
    Join Date
    Aug 2005
    Location
    Looking down & checking on swearing
    Posts
    19,378
    Thanks
    2,892
    Thanked
    3,403 times in 2,693 posts

    Re: Quick egrep problem

    Does it work if you escape the special characters?
    (\__/)
    (='.'=)
    (")_(")

    Been helped or just 'Like' a post? Use the Thanks button!
    My broadband speed - 750 Meganibbles/minute

  4. #4
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Re: Quick egrep problem

    Quote Originally Posted by peterb View Post
    Does it work if you escape the special characters?
    I don't know how to do that when recursively searching through a directory tree...
    Am I right in thinking that if I was searching a specific file then I could just do something like the following?

    Code:
    grep "string" /media/windows-share/folder/subfolder/file\-name.doc

  5. #5
    The late but legendary peterb - Onward and Upward peterb's Avatar
    Join Date
    Aug 2005
    Location
    Looking down & checking on swearing
    Posts
    19,378
    Thanks
    2,892
    Thanked
    3,403 times in 2,693 posts

    Re: Quick egrep problem

    Yes - I think

    Code:
    grep "string" /media/windows-share/folder/subfolder/file\-\name.doc
    or you might be able to double quote the string

    something like

    Code:
    grep "string" /media/windows-share/folder/subfolder/"file-name.doc"
    However I am very much a novice at scripting.
    (\__/)
    (='.'=)
    (")_(")

    Been helped or just 'Like' a post? Use the Thanks button!
    My broadband speed - 750 Meganibbles/minute

  6. #6
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Re: Quick egrep problem

    I guess that if I'm recursively searching down through a whole folder structure and don't know what the file names are (or if they will contain restricted chars) then I'll need to take a different approach.....

  7. #7
    mush-mushroom b0redom's Avatar
    Join Date
    Oct 2005
    Location
    Middlesex
    Posts
    3,438
    Thanks
    174
    Thanked
    362 times in 279 posts
    • b0redom's system
      • Motherboard:
      • Some iMac thingy
      • CPU:
      • 3.4Ghz Quad Core i7
      • Memory:
      • 24GB
      • Storage:
      • 3TB Fusion Drive
      • Graphics card(s):
      • nViidia GTX 680MX
      • PSU:
      • Some iMac thingy
      • Case:
      • Late 2012 pointlessly thin iMac enclosure
      • Operating System:
      • OSX 10.8 / Win 7 Pro
      • Monitor(s):
      • Dell 2713H
      • Internet:
      • Be+

    Re: Quick egrep problem

    find . | xargs grep -i "string"

    ?

  8. #8
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Re: Quick egrep problem

    Quote Originally Posted by b0redom View Post
    find . | xargs grep -i "string"
    I'll have a play with that in a bit....thanks

  9. #9
    Senior Member
    Join Date
    Mar 2005
    Location
    North East
    Posts
    400
    Thanks
    5
    Thanked
    12 times in 12 posts

    Re: Quick egrep problem

    The reason that you see the error messages on your console is that they are output on stderr and not stdout. You can re-direct stderr to stdout so that it ends up in your log file by appending 2>&1 to your command.

  10. #10
    Senior Member
    Join Date
    Dec 2005
    Location
    ::1
    Posts
    204
    Thanks
    4
    Thanked
    9 times in 8 posts
    • chinny's system
      • Motherboard:
      • Asus P5Q-EM
      • CPU:
      • Intel E6300
      • Memory:
      • 4Gb Corsair XMS2
      • Operating System:
      • Win7 x64

    Re: Quick egrep problem

    Thanks for the reply KowShak. I did a quick search on that and came across http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html which explains stdin, stdout and stderr.....I'll have a play with that when I get a minute as well.

    Many thanks all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. quick php problem
    By nvening in forum Software
    Replies: 11
    Last Post: 07-10-2009, 07:09 PM
  2. ECS 910 / Advent 7080 White Screen and no VGA problem Notebook Laptop
    By David R in forum PC Hardware and Components
    Replies: 0
    Last Post: 18-06-2007, 05:52 AM
  3. Fatality FP-IN9 resume from S3 problem
    By $kunk in forum abit.care@HEXUS
    Replies: 0
    Last Post: 22-05-2007, 04:07 PM
  4. SN25P PSU or PCI-E problem!?
    By SilverFern in forum PC Hardware and Components
    Replies: 1
    Last Post: 19-01-2006, 10:51 AM
  5. Replies: 23
    Last Post: 08-08-2005, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •