Grep doesn't find what it should

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep doesn't find what it should
# 1  
Old 07-22-2016
Grep doesn't find what it should

Dear all,


I wanted to use grep to search some files containing code - and the result was very disappointing: although I could see with my own eyes the expressions (written in the files), grep didn't give any output.

Basically, I write this to the terminal
Code:
grep "Find" *.txt

or
Code:
grep Find *.txt

in a folder in which some txt files have the word Find in them. Some file also contain some variants like Find, ["Find"], ["FindAllChi..."], etc. I don't get any output, i.e. grep doesn't say file blablabla.txt contains Find or bla2.txt contains FindAllCh..


If I'm editing a file to contain just one line of code, grep finds what I'm looking for.


Can you give some suggestions on how to make grep working?
Thank you!



PS I'm using cygwin 2.5.1(0.297/5/3) on a 64 bits Windows 7 machine.
# 2  
Old 07-22-2016
Please post (reduced) sample input files and error messages. Could it be locale dependent, or character set dependent?
# 3  
Old 07-22-2016
If this problem occurs on a Windows system, I would start by looking for extraneous <carriage-return> characters in the script you're running. For example if the grep line in the script is:
Code:
grep Find *.txt<CR>

where <CR> is a carriage-return character, instead of:
Code:
grep Find *.txt

the only you're likely to get is a diagnostic saying it can't open a file named *.txt<CR>
and the <CR> in the diagnostic will be invisible unless the diagnostic quotes the filename (in which case you end us with a quote at the start of the diagnostic instead of at the end).

Please show us the output from the command:
Code:
od -bc script_name

where script_name is the name of your shell script containing the grep command. (And, obviously, please show us all of the output produced when you run your script and the exact command line you used to invoke your script.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep doesn't work when assigning to variable

Hello, First of all, I'd like to say hello to all members of forum. Can You please help me with the matter described below? I am trying to fetch a data from the file to variable, I am doing this using below script: returned=`tail -50 SapLogs.log | grep -i -E "Error|"` echo $returned ... (2 Replies)
Discussion started by: jedzio
2 Replies

2. Red Hat

Grep doesn't understand escape sequence?

I ran the following grep and sed command. grep "\t" emp.txt sed -n '/\t/p' emp.txt grep treated the '\' as to escape t and took the pattern as literal t whereas sed took the pattern as tab. That means , grep doesn't understand escape sequence!!!!!! what to do to make grep... (8 Replies)
Discussion started by: ravisingh
8 Replies

3. Shell Programming and Scripting

pipe to grep doesn't work in bash script

Hi, I'm trying to write a script that checks gvfs to see if a mount exists so I can run it from network-manager's status hooks. I thought I'd pipe the output of gvfs-mount -l to grep for the particular mounts I care about. When I do this in a bash script: cmnd="gvfs-mount -l | grep -i... (4 Replies)
Discussion started by: kcstrom
4 Replies

4. Programming

find() doesn't find '|' for some reason

Here's some sample output and my code follows it. Why can't find() find '|'. It just dosn't make a bit of sense at all. AL01463|Pell City|Saint Clair|B|02115|AL|35125|630|Birmingham (Ann and Tusc)|13890|40|Charter Communications|Fairfield|Charter Communications|2 -1... (1 Reply)
Discussion started by: sepoto
1 Replies

5. Shell Programming and Scripting

tail -XXX with grep doesn't work in while loop

Hi all, I need some help. my shell script doesn't work especially in the loop. #!/bin/sh -xv export ORA_ADMIN=/oracle/home/admin export ORACLE_SID=ORA_SID cat ${ORA_ADMIN}/param_alert_log.ora | while read MSG do #echo $MSG #echo "tail -400... (8 Replies)
Discussion started by: sidobre
8 Replies

6. Shell Programming and Scripting

two grep in one script doesn't work?

Hi there, the following script doesn't work. the first part works, then the second 'grep' fails with ': not found'. However, if I take out the second part (starting with the grep command) and put in a seperate script, it works. everyone know what's wrong here? no two 'grep' in one script, that... (2 Replies)
Discussion started by: monkey77
2 Replies

7. UNIX for Dummies Questions & Answers

For some reason, my grep doesn't work as expected

I am trying to find only those entries where 7018 and another number appear in the end of the line. 7018 2828 1423 2351 7018 2828 14887 2828 7018 1222 123 7018 1487 I am looking for a way to generate only the last two lines. I was trying to do just "grep '7018{1,5}" but it does not... (5 Replies)
Discussion started by: Legend986
5 Replies

8. Solaris

grep -e doesn't work on solaris

grep -e doesn't work in Soalris. Same script with grep -e worked on AIX/HP/LINUX.. I would like to search a list of patterns on "log.txt" like ... grep -e FATAL -e ERROR log.txt I get the error message as grep: illegal option -- e Usage: grep -hblcnsviw pattern file . . . (3 Replies)
Discussion started by: jmkraja
3 Replies

9. Shell Programming and Scripting

perl - how do i find out if a file doesn't contain a pattern?

how do i check a file for a pattern and perform an action if it doesn't exist? i know how to search a file for a pattern. you just place it in an array like so. #!/usr/bin/perl my $data_file = "file.txt"; open DATA, "$data_file"; my @array_of_data = <DATA>; if ($_ =~ m/pattern/i) {... (4 Replies)
Discussion started by: mjays
4 Replies

10. Shell Programming and Scripting

grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong. When I copy and paste it to the terminal, it is OK. Any idea what the problem might be? set i = `grep -c #define flags.h` while ($i>20) @ i-- my func (`cat... (4 Replies)
Discussion started by: barisgultekin
4 Replies
Login or Register to Ask a Question