LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2015, 04:50 PM   #1
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 23

Rep: Reputation: Disabled
GREP: only for text files? What am I doing wrong?


I thought the command:

grep -a -i -r "Linux is" /media/hd/doc/computer/

would find the text string Linux is in all files in /media/hd/doc/computer/ and subdirectories.

But it's not! It finds Linux is only in text files. The -a switch isn't doing what I thought it would do. I know that Linux is is in several .doc and .odt files, but grep doesn't report them.

Am I doing something wrong? Using a utility for an unintended purpose? Can anyone suggest a better utility for hunting for text in .doc files?
 
Old 12-26-2015, 05:12 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Most likely, the string is not exactly stored in this way in a doc or odt file. Perhaps the blank is something else than an ASCII 32. You can check that with the od command or a binary editor.

The only recommendation I have is OpenOffice or LibreOffice. They might have non-GUI utilities.
 
1 members found this post helpful.
Old 12-26-2015, 07:48 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Neither .doc nor .odt are text files - ergo you can't simply search them as text.
A simple online search should have informed you of this.

For odt, try unzip before the grep, for .doc look at catdoc.
 
Old 12-26-2015, 08:12 PM   #4
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 23

Original Poster
Rep: Reputation: Disabled
First, FWIW: the search string:

grep -a -i -r "Linux" /media/hd/doc/computer/

also comes up empty. Thank you, though, berndbausch, for suggesting that the string might be stored differently; I hadn't thought of that.

This page at serverfault told me I can grep my way through binary files with the -a switch:

https://serverfault.com/questions/32...look-like-text

Did I misunderstand something? (Wouldn't be the first time ...)

I'll experiment with catdoc, syg00; thank you for this recommendation.
 
Old 12-26-2015, 09:10 PM   #5
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 23

Original Poster
Rep: Reputation: Disabled
It looks like Recoll can do the job:

http://www.lesbonscomptes.com/recoll/
 
  


Reply

Tags
grep



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep text from remote log file, enter text and rename on remote server vanish78 Linux - Newbie 1 07-30-2012 05:32 PM
grep a text in files and print the file name who don't contain such text whossa Linux - Newbie 5 04-13-2012 07:49 AM
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 11:42 AM
join 2 text files based on first number present in every line of the 2 text files markraem Linux - Software 4 01-25-2010 06:26 AM
To grep a text from a list of files. ZAMO Linux - General 4 04-03-2008 07:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration