Strange error: grep does not read from file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Strange error: grep does not read from file
# 1  
Old 09-20-2011
Strange error: grep does not read from file

I have two files
file1.txt
Code:
angie
mary
susan

file2.txt
Code:
angie blond
mary brunnet
susan red
christine black

I want to get this output
Code:
angie blond
mary brunnet
susan red

I write
Code:
grep --file=file1.txt file2.txt

and i get no results

i also wrote
Code:
cat file1.txt|while read line file1.txt;do grep "$line" file2.txt;done

again no results

I tried
Code:
while read line file1.txt;do echo -e "$line";done

nothing

but when i write
Code:
while read line;do echo -e "$line";done<file1.txt

it reads the lines


I don't understand that, why it does not read the input files inside the code?

If i solve this i will be able to run the first command, right?
# 2  
Old 09-20-2011
Should be:
Code:
cat file1.txt|while read line ;do grep "$line" file2.txt;done

But your last example is maybe better still...
# 3  
Old 09-20-2011
Hi, Use grep with option -f

grep -f file1.txt file2.txt.

Hope it should work.
# 4  
Old 09-20-2011
Quote:
Originally Posted by vbe
Should be:
Code:
cat file1.txt|while read line ;do grep "$line" file2.txt;done

But your last example is maybe better still...
I tried but it does not work...

---------- Post updated at 09:38 AM ---------- Previous update was at 09:38 AM ----------

Quote:
Originally Posted by Abhishek_1984
Hi, Use grep with option -f

grep -f file1.txt file2.txt.

Hope it should work.
It does not work either....
# 5  
Old 09-20-2011
Who are you kidding?
Code:
ran:/home/vbe $ cat file1.txt|while read line ;do grep "$line" file2.txt;done
angie blond
mary brunnet
susan red

# 6  
Old 09-20-2011
Quote:
Originally Posted by vbe
Who are you kidding?
Code:
ran:/home/vbe $ cat file1.txt|while read line ;do grep "$line" file2.txt;done
angie blond
mary brunnet
susan red

for me it does not work, with the actual files i have.
That is why i wrote "strange" in the beginning. I've run it before and it worked fine
but i do not know what could be wrong now.
# 7  
Old 09-20-2011
I created exactly the files with the given names and content...
So start to see if the cat command part works or check your perms on those files try to give var name using UPPERCASE which will prevent you to having to look for reseved words or aliases...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help for faster file read and grep in big files

I have a very big input file <inputFile1.txt> which has list of mobile no inputFile1.txt 3434343 3434323 0970978 85233 ... around 1 million records i have another file as inputFile2.txt which has some log detail big file inputFile2.txt afjhjdhfkjdhfkd df h8983 3434343 | 3483 | myout1 |... (3 Replies)
Discussion started by: reldb
3 Replies

2. Shell Programming and Scripting

How to read each file grep a value from that?

Hi Team, in /tmp folder i have thousands of log files i want to read each file and grep a value called "Calling This". Each logfile name is different but it ends with .log. How can i achieve this? Please excuse if i did any mistake by not following forum standards. I will surely follow... (10 Replies)
Discussion started by: darling
10 Replies

3. UNIX for Beginners Questions & Answers

Read a file and send mail based on grep

Hi All, I am having a job and I need to send email when the job is running. On any other case (success,fail) I don't needed to send email. I check with BMC they told they dont have that in the version I am using. So I created a dependent job and grepped for the status and sent email. My... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

4. Shell Programming and Scripting

read from file and grep using shell

Hi Guys, I have a small script which greps for the username reading from stdinput. ./file.sh pattern pattern=$1 grep "blah blah.*$pattern" /home/user/log.txt Instead of typing the pattern everytime i want to read the pattern from a file inside the shell script and execute the... (5 Replies)
Discussion started by: Irishboy24
5 Replies

5. Shell Programming and Scripting

Grep a file that may contain strange characters

Hello unix users :) I am trying to grep a string from a file that both the file and the string may have characters in them that are quite... strange, like würzburger. Well, bash reads this as W%C3%BCrzburger For example, if i do wget W%C3%BCrzburger the output is: --2012-01-08... (2 Replies)
Discussion started by: hakermania
2 Replies

6. Shell Programming and Scripting

Strange error while splitting a file

Hi folks I am facing a strange error while splitting a '|' delimited file 'file1' based on column '3'. (File is 40 columns wide). I wish to create as many files 'file_n' from the file 'file1' as distinct values of the column '3'; in 'file1' eg: file1: qwe|qweqw|123|fg... (3 Replies)
Discussion started by: powerslave
3 Replies

7. Shell Programming and Scripting

read in variable data from another file - grep

Hello! I think this should be an easy solution. I have a large file with many fields of data. The first field has a unique identifier (a subject number) for every record for a chunk of data. Something like this: There were ten experimental conditions (ec), but the ec is identified by only... (11 Replies)
Discussion started by: ccox85
11 Replies

8. UNIX for Advanced & Expert Users

Strange read "error"

Good day. I really hope U can help me with this as I'm stumped! In the command line eg: read X; echo $x . Works perfectly fine. Then running the same thing in my script it sometimes exiqute immediatly after pressing enter and continuiing. Not exiting the script I re-run the "read" section.... (1 Reply)
Discussion started by: Blooper1980
1 Replies

9. Shell Programming and Scripting

Read file then grep the line

Dear all, I am reading a file that has 1 column. While reading I must find the line references from the another file. The following shell doesn't works. Please help #!/bin/bash while read filename; do grep ${filename} fs_full.dat >> unprocfull.dat; done < unproc.dat But when... (2 Replies)
Discussion started by: mr_bold
2 Replies

10. AIX

Strange error with file access permissions

All, I am trying to copy some data from /admin/reports/Sept/ccn/c_ivsstr01 to /home/users/myhomedir and I am getting an error I have never seen before: The file access permissions do not allow the specified action. The permissions on the file are -rw-r--r-- and I am the owner of the file... (3 Replies)
Discussion started by: kjbaumann
3 Replies
Login or Register to Ask a Question