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
# 8  
Old 09-20-2011
Just wondering...
What key stoke do you use to get the pipe?
Ctrl-1 or Alt GR-7
# 9  
Old 09-20-2011
My mitake instead of grep use egrep

egrep -f test1 test2
angie blond
mary brunnet
susan red


I am getting the requird result.

---------- Post updated at 10:17 AM ---------- Previous update was at 10:15 AM ----------

Hi, instead of grep you have to use egrep

egrep -f test1 test2
angie blond
mary brunnet
susan red

I am getting the required result
# 10  
Old 09-20-2011
Quote:
Originally Posted by vbe
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...
When i type this
Code:
while read line file1.txt; do echo -e "$line";done

it does not work
when i type this

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

it does work.

Could this be helpful?

For the other part, you mean to rename the files to uppercase letters?

---------- Post updated at 10:33 AM ---------- Previous update was at 10:31 AM ----------

Quote:
Originally Posted by Abhishek_1984
My mitake instead of grep use egrep

egrep -f test1 test2
angie blond
mary brunnet
susan red


I am getting the requird result.

---------- Post updated at 10:17 AM ---------- Previous update was at 10:15 AM ----------

Hi, instead of grep you have to use egrep

egrep -f test1 test2
angie blond
mary brunnet
susan red

I am getting the required result
Neither the egrep works

---------- Post updated at 10:33 AM ---------- Previous update was at 10:33 AM ----------

Quote:
Originally Posted by vbe
Just wondering...
What key stoke do you use to get the pipe?
Ctrl-1 or Alt GR-7
Sorry, i did not understand what you mean...
# 11  
Old 09-20-2011
Yes first example does not work because its a non sence...
read command reads something, a VAR a line from input ( and so cant read a file, but cat does...)
I mean by uppercase e.g.
Code:
cat file1.txt|while read LINE; do echo -e "$LINE";done

Addendum...
I ment depending from where you come from and what keyboard layout you have, you may not choose the correct one... For the only reason I saw at that time for the line to not work was the | (for me here it would be AltGr+ 7 keys to depress)
# 12  
Old 09-20-2011
Quote:
Originally Posted by vbe
Yes first example does not work because its a non sence...
read command reads something, a VAR a line from input ( and so cant read a file, but cat does...)
You can definitely read a line from a file in a while loop:
Code:
while read LINE
do
        echo -e "$LINE"
done < file1.txt

This will also prevent side-effects like variables being set inside the loop not being seen outside it.
# 13  
Old 09-20-2011
Corona688:
You are absolutely right but that, our member already knows and tried ( see the beginning of thread...and I also sugggested was better...) but what he could not understand what was incorrect in his example giving a
Code:
read VAR <a file>

Maybe could you explain to our guest the reason or how works the redirection ( I wonder if its not there the confusion - where in input using < you specify a file, but doesnt work with read <variable> file...)

Last edited by vbe; 09-20-2011 at 12:54 PM.. Reason: addendum : task for corona688 if he accepts...
# 14  
Old 09-20-2011
Quote:
Originally Posted by Corona688
You can definitely read a line from a file in a while loop:
Code:
while read LINE
do
        echo -e "$LINE"
done < file1.txt

This will also prevent side-effects like variables being set inside the loop not being seen outside it.
It may sound silly but, since i want to use grep i actually want two input files, file1.txt and file2.txt

How do I do this? I mean in my case the command
Code:
cat file1.txt|while read line; do grep "$line" file2.txt;done

does not give me result. When i use the < though to set the input file it works.
So i wonder how can i do this with my two input files?
I hope i am not very confusing but i have no idea why WITH THE PARTICULAR FILES it does not work
 
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