text serach in unknown file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users text serach in unknown file
# 8  
Old 10-22-2003
new maths??

Hi! Perderabo,

Excellant Analysis..
# 9  
Old 10-22-2003
Perderabo,

How do you get 746 files for the 2 character names? 254 *2 is 508...



___________________________________
one other way that is a simple loop...

cd /dir/to/check/

for name in `ls *`
do
grep "where john is going" $name
done > file.out 2>err.out

This will capture the output in a file and any errors.

Last edited by Kelam_Magnus; 10-22-2003 at 04:08 PM..
# 10  
Old 10-22-2003
Quote:
Originally posted by Kelam_Magnus
Perderabo,

How do you get 746 files for the 2 character names? 254 *2 is 508...



___________________________________
one other way that is a simple loop...

cd /dir/to/check/

for name in `ls *`
do
grep "where john is going" $name
done > file.out 2>err.out

This will capture the output in a file and any errors.
The thread that would not die... Smilie

First, your "ls *" is going to have the same problem. There too many filenames to build the list all at once.

As for how I did the math. We want to build a list of 1000 filenames and we want the list to be as short as possible. We start by using as many 1 character filenames as possible. There are 256 possible values for a byte. But you can't use null for a filename. Nor can you use /. So that gives us 254 possible 1 character filenames. But we want 1000 filenames. 1000 - 254 = 746. We still need 746 more filenames. We will make those 2 characters long because we want the list as short as possible. At this point, we have (254 + (2 * 746)) = 1746 characters in our list of filenames. But we can't run the names together. We need a space between the names and that takes 999 spaces. So 1746 + 999 = 2748 is the shortest possible list of 1000 files.

Now here is a confession... my logic that jyotipg praised has a flaw. And the correct answer is actually 2751. But I won't tell why. I know that you'll enjoy finding my flaw on your own. Smilie
# 11  
Old 10-22-2003
ROFL

I just realized 1000 - 254 =756 hehe... sorry long day... basic math here...

Yes I realized that the ls * was the same mistake... after i posted it. That works better on directories where there are not normally 1000 files in the dir...


also, 1746 + 999 = 2745, not 2748 Smilie You had that right in your previous post... +2 bytes for the command "l " gives you 2747... which was your first answer as well...

not sure I can see the flaw, Im kinda out of it today...
# 12  
Old 10-23-2003
original post by kelas_magnum
===========================
also, 1746 + 999 = 2745, not 2748 You had that right in your previous post... +2 bytes for the command "l " gives you 2747... which was your first answer as well...
============================

magnum,
you missed out adding 1 byte for the space between "ls" and "*". That makes it 2747 + 1 = 2748 as originally said by perderabo.

But I cant understand the mystery behind the magic number of "2751".. Smilie
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