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
# 15  
Old 09-20-2011
If you look at my previous posts, you will see the output where I showed you it works
# 16  
Old 09-20-2011
Code:
ran:/home/vbe $ ll -lt|grep file                                             
-rw-rw-rw-   1 vbe        bin             51 Sep 20 16:55 file2.txt
-rw-rw-rw-   1 vbe        bin             17 Sep 20 16:55 file1.txt
-rw-rw-rw-   1 vbe        bin             44 Nov 11  2010 filename
ran:/home/vbe $ cat file*txt
angie
mary
susan
angie blond
mary brunnet
susan red
christine black
ran:/home/vbe $ cat file1.txt|while read line ;do grep "$line" file2.txt;done
angie blond
mary brunnet
susan red
ran:/home/vbe $

# 17  
Old 09-20-2011
Perhaps the files processed are not in unix file format ?
Please check that.

Regards
Peasant.
# 18  
Old 09-20-2011
I suggest that the OP provide an unambiguous dump of his/her text file, using hexdump -C, od -bc, or whatever tool is available to give us a definitive manifest of the files' contents.

The following is an example of data that appears fine when sent to the terminal but thwarts grep's attempt to match it:
Code:
$ printf 'a\000bc\n'
abc
$ printf 'a\000bc\n' | grep abc
$

Also, it wouldn't hurt to post a trace of your shell's actions. Assuming you're using a posix-like shell, you can probably enable tracing with set -x (you can then disable it with set +x).

Regards,
Alister
# 19  
Old 09-21-2011
Quote:
Originally Posted by Peasant
Perhaps the files processed are not in unix file format ?
Please check that.

Regards
Peasant.
Can you please tell me how to do that?
Thank you

---------- Post updated at 03:42 AM ---------- Previous update was at 03:39 AM ----------

Maybe its better to provide my actual data to see if i find a solution
file2.txt
Code:
Les.1000.1.A1_at    BG628706
Les.1007.1.A1_at    BG628731
Les.1008.1.A1_at    BG628739
Les.1009.1.A1_at    BG628745
Les.101.1.S1_at    AJ002298.1
Les.1011.1.A1_at    BG628754
Les.1013.1.A1_at    BG628758
Les.1015.1.A1_at    BG628777
Les.1018.1.A1_at    BG628791
Les.1019.1.A1_at    BG628793
Les.102.1.S1_at    AF022874.1

file1.txt
Code:
Les.1013.1.A1_at
Les.1015.1.A1_at

---------- Post updated at 04:09 AM ---------- Previous update was at 03:42 AM ----------

There is probably something wrong with the file "encoding", originally it is an excel file from windows
# 20  
Old 09-21-2011
I get:
Code:
ran:/home/vbe $ cat file1.txt|while read line ;do grep "$line" file2.txt;done
Les.1013.1.A1_at    BG628758
Les.1015.1.A1_at    BG628777

So you do the same: do a copy paste if you can from your post, dont edit just copy /paste straight to your unix box but can you ? (Im using ReflectionX...).
 
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