LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 05:50 PM   #1
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 13

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, 06:12 PM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,688

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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, 08:48 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,052

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
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, 09:12 PM   #4
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 13

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, 10:10 PM   #5
Adams Seven
LQ Newbie
 
Registered: Sep 2015
Distribution: Linux Mint 17.2
Posts: 13

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

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


Reply

Tags
grep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06: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 08:49 AM
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 12:42 PM
join 2 text files based on first number present in every line of the 2 text files markraem Linux - Software 4 01-25-2010 07:26 AM
To grep a text from a list of files. ZAMO Linux - General 4 04-03-2008 08:10 AM


All times are GMT -5. The time now is 04:35 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration