Grep returns nothing

Hi all,

I am trying to grep a .txt file for a word. When I hit enter, it returns back to $

The file is 4155402 in size and is named in this way:

*_eveningtimes_done_log.txt

I use this command, being in the same directory as the file:

grep -i "invalid" *_eveningtimes_done_log.txt

and it returns back to $

It pretty much means that the string you are searching for was not found.
To be sure that is the case tell us what is the output of

grep -ci "invalid" *_eveningtimes_done_log.txt

?

The string does exist. If i do a head -50 , then i can see the string. I can also see it via opening the file in windows text editor.

Can you post those 50 lines (obfuscating any private data)? It might be that you have some hidden characters. You can use cat -v to check this.

here is the output:

po8897hg

What environment are you running the grep command in?

bash-3.2$ ?

Can you tell me how to check that?

---------- Post updated at 02:17 PM ---------- Previous update was at 02:13 PM ----------

0 value is returned.

Probably linux then. My next guess would be that the shell glob isn't covering all the files you think it is. What is the exact command you're typing for head?

head -50 (file name)

I mean, literally, what you type for head, character by character. (file name) isn't your real filename so I can't tell if your glob's wrong.

head -50 153_eveningtime_done_log.txt

grep -ci "invalid" *_eveningtimes_done_log.txt
head -50 153_eveningtime_done_log.txt 

There you go. :slight_smile:

Didnt work.

Did you try to copy these 50 lines in a new file and run grep again?
It worked for me. If it works for you too, than there may be something wrong with the *.txt file.
Maybe it's created on Windows and needs to run through dos2unx first or the like?

copying the file the contents of the file and saving it to a different location with same name makes grep work.

but i cannot perform this copy function everyday.

doing dos2unix on the actual file did not help.

what other ways can i search for a string instead of grep?

If following doesn't work, than I really don't know any other solution.

$ cat 153_eveningtime_done_log.txt | grep -i "invalid"

If there is nothing sensitive in the data file, why not attach it to a post so that everyone can examine it? Or, remove extraneous lines until you have created a minimal file, free of sensitive information, that still "misbehaves" when grepped, and attach that. In either case, do not copy/paste as that can modify the data.

If you do attach a file, please make sure to mention which operating system you are using? And, if you know, which implementation of grep (if this is a linux system or cygwin, it's almost certainly gnu's grep).

Alternative ways to search a file for a word include sed, awk, sh read/case glob, perl, python, ... etc. Although, if that were my file, I'd really want to know what is going on. Without knowing what's going on, you could be experiencing other false negatives and not even know it.

Regards,
Alister