text serach in unknown file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users text serach in unknown file
# 1  
Old 09-05-2003
text serach in unknown file

Can any one tell me if there is an easy way to find a text in an unknown file name in a dierectory.

I'm trying to search for the text "where is john going" from a file
whose name I do not even know. There are about 1000 files in that directory and one of the files has this text in it.

Can any one tell me how I can achive this?


Thanks,
Ted
# 2  
Old 09-05-2003
ls | xargs grep -l "where john is going"
# 3  
Old 09-05-2003
And if they're in more than one directory, you could use this in the top directory:

find . -exec grep -l "where john is going" {} \;
# 4  
Old 09-08-2003
cd /into/your/dir

grep "where john is going" *


Regs David
# 5  
Old 09-08-2003
Quote:
Originally posted by davidg
cd /into/your/dir
grep "where john is going" *
That is guaranteed to fail on most systems. You are asking the shell to replace * with a list of "about 1000 files". A command line must be less than LINE_MAX which is often 2048.
# 6  
Old 09-08-2003
Hi perderabo,

You're right. In this case it would have been ok probably as it are only 1000 files, but in case of extreme large directories, this indeed fails.
Better to stick to the other solutions then, or just remember that it might fail once.

Regs David
# 7  
Old 09-08-2003
New Math?

Quote:
Originally posted by davidg
In this case it would have been ok probably as it are only 1000 files, but in case of extreme large directories, this indeed fails.
Since the files reside in the same directory they must have unique names. There are only 254 values that can reside in a byte used as a filename. After you max out the 1 character filenames, you will need 746 two character filenames. 746 * 2 + 254 = 1746. And now you need 999 spaces to separate them... 1746 + 999 = 2745. So if you're willing to tolerate a lot of unprintable filenames, you can get 1000 names into a list that is 2745 bytes long, but that is the absolute minimum. And you still need 2 bytes to have a one character command.

This is not probably ok, it is guaranteed to fail on a system with LINE_MAX set to 2048.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

How to get a value from a file and serach that value filename in a dir?

buddies, my requirement would be as follows, I have a file called test.txt and content of it would be yahoo gmail hotmail and i want to search a file name called "yahoo.html" (first line of test.txt) and then "gmail.html" and then "hotmail.html" in a /home/test dir. Any idea... (8 Replies)
Discussion started by: natraj005
8 Replies

3. Shell Programming and Scripting

Serach a string for multiple occurrences in a file and cut related texts

Hi, I want a help in this forum for my below issue. 1. I have a file where I'm searching for a text . 2. When I get the line where the above string is present I want to cut some texts from the line where the particular string was found. These above two steps will repeat in the... (2 Replies)
Discussion started by: bhaski2012
2 Replies

4. Shell Programming and Scripting

How to serach for Values grater tan 4 digits in a file using Awk Command

Dear All iam looking for a help in how to search for values grreater than 4 numbers. I run the below commad but its still not working awk '{ print $2 " " $5 }' AllRecords | grep "+008" | grep "length" > 4 Can any one help me. Regards Kadir (1 Reply)
Discussion started by: samura
1 Replies

5. Shell Programming and Scripting

serach and replace a specific pattern or value in a xml file

can some one help me with a perl command i have to search and replace a version from a xml-file so i use in a ksh script a command like this ssh $GLB_ACC@$GLB_HOST "/usr/contrib/bin/perl -pi -e "s/$curVersion/$new_Version/g" $Dest_dir/epi.xml" this command worked so far, but the problem... (1 Reply)
Discussion started by: kiranreddy1215
1 Replies

6. Solaris

PING - Unknown host 127.0.0.1, Unknown host localhost - Solaris 10

Hello, I have a problem - I created a chrooted jail for one user. When I'm logged in as root, everything work fine, but when I'm logged in as a chrooted user - I have many problems: 1. When I execute the command ping, I get weird results: bash-3.00$ usr/sbin/ping localhost ... (4 Replies)
Discussion started by: Przemek
4 Replies

7. UNIX for Dummies Questions & Answers

Need to serach if a new line character exists on the last line in a file

I have a file in which I need to search if a new line character exists on the last line in the file. Please let me know how can I achieve it using Unix commands? (10 Replies)
Discussion started by: sunilbm78
10 Replies

8. Shell Programming and Scripting

serach and replace file name in the path in a remote xml file

hi every one , here is my problem !! i have to run my script from an account and update the result in a xml file located on a different account. i use existing ssh keys to do it remotely for example the tags looks like this <PropertyValueList... (1 Reply)
Discussion started by: kiranreddy1215
1 Replies

9. Shell Programming and Scripting

serach file using awk

Hi, I was able to print lines when search for specific string using awk but i want to print when search for two different strings using awk instead of doing two times (Print lines only contain "Insert Records and Insert into" not between lines) Ex: awk '/Insert Records./' a4.log It... (3 Replies)
Discussion started by: mohan705
3 Replies

10. UNIX for Dummies Questions & Answers

automatic tar xf of file with unknown name

Hi all, With curl I can fetch a tar archive from a web server which contains a file ending with .scf which I am interested in. Unfortunately the file name may vary and the subdirectory inside the tar archive may change. I can manually browse the directory structure and extract the file and then... (3 Replies)
Discussion started by: tkrahn
3 Replies
Login or Register to Ask a Question