LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-07-2004, 06:23 AM   #1
guarriman
Member
 
Registered: Nov 2004
Posts: 101

Rep: Reputation: 15
A cool script to search within a hell of TXT files


Hi.

I've got 1000s of TXT files within a directory, and I would like to
find
a cool script to search within it.

I want to search files which content 'Foo' but not 'John', and only
within the '20041129' subdirectory.

I don't know if I must develop my own script or it already exists.

BTW, can I integrate this script into a Apache module?

Thank you very much.
 
Old 12-07-2004, 06:39 AM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
grep -r foo 20041129/ | grep -v john

To integrate this into apache, make script containing lines:
Code:
#!/bin/sh
echo -e 'Content-Type: text/plain\n\n'
grep -r foo 20041129/ | grep -v john
 
Old 12-07-2004, 06:39 AM   #3
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
Hey

You could just grep through it to find which files contain "foo", but not "John". If you cat the result to a text file which will show you the path.

Code:
$ echo "$(grep -Eir Foo /home/guarriman/20041129/* |  grep -Eirv John)" > temp_file
This will put all the output in "temp_file" and will show you the path.

You could also find a way just to print the path, but i don't know how to do that atm.

Hope this helps.

hamish
 
Old 12-07-2004, 06:40 AM   #4
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
lol, I see I was too late.

H
 
Old 12-07-2004, 06:41 AM   #5
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
ToniT,

how do you integrate that code into apache? Is it possible to create a web page whereby someone clicks a "show me all file containing Foo" link, and that code is executed.

That seems quite insecure, though.

Hamish
 
Old 12-08-2004, 12:17 AM   #6
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Hamish:
By saving that file to eg. foo.cgi and enabling cgi support from apache.
 
Old 12-08-2004, 03:48 AM   #7
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
and then do you have a link which calls the foo.cgi file?
H
 
Old 12-08-2004, 07:21 AM   #8
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
test it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
Bash, how do I test for *.txt files in a directory with IF? severian23 Programming 7 11-04-2004 09:47 AM
I can only print ps/txt files ? TroelsSmit Linux - Newbie 3 09-12-2004 01:15 PM
Perl Script Reading a txt file and generate html to be published! kofi Linux - Software 1 09-22-2003 05:12 PM
Convert Powerpoint files to txt,html..... devinWhalen Linux - Software 0 07-29-2003 12:12 PM


All times are GMT -5. The time now is 01:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration