LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-23-2009, 01:10 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Rep: Reputation: 30
need a php script to format and display a select amount of text from a file


hey i need a php script to format and display a select amount of text from a file or a cron job that'll do it (with grep etc) and out put to a file but whatever is easier

i want to display all the banned ip's i have in my .htaccess file

i have a lot of lines in my .htaccess file but i have a line that read like this:

Code:
RewriteCond %{REMOTE_ADDR} (123\.123\.123\.123|123\.123\.123\.123|123\.123\.123\.123)$
the 3 test ip's are 123.123.123.123 and i want the "\" stripping and the "|" removing and each ip to be on it's own line like this:

123.123.123.123
123.123.123.123
123.123.123.123

i'm not bothered if this is a php script that'll read the .htaccess file and display the output or a cron job that'll run every x mins and output it to a .txt file but i'd prefer a php script

can anyone help me with this please?

Last edited by steve51184; 01-23-2009 at 01:13 PM.
 
Old 01-23-2009, 02:14 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
hey i need a php script to format and display a select amount of text from a file or a cron job that'll do it (with grep etc) and out put to a file but whatever is easier

i want to display all the banned ip's i have in my .htaccess file

i have a lot of lines in my .htaccess file but i have a line that read like this:

Code:
RewriteCond %{REMOTE_ADDR} (123\.123\.123\.123|123\.123\.123\.123|123\.123\.123\.123)$
the 3 test ip's are 123.123.123.123 and i want the "\" stripping and the "|" removing and each ip to be on it's own line like this:

123.123.123.123
123.123.123.123
123.123.123.123

i'm not bothered if this is a php script that'll read the .htaccess file and display the output or a cron job that'll run every x mins and output it to a .txt file but i'd prefer a php script

can anyone help me with this please?
You can check out the explode function (http://us2.php.net/manual/en/function.explode.php), which should be able to do what you're looking for in PHP.

However, in SED via a small bash script, it's easy too:

sed 's/\\//g' - Will strip out the '\' character.
sed 's/\|/\n/g' - Changes the '|' to a newline.

Check, though...doing this from memory..untested..your mileage may vary.
 
Old 01-23-2009, 02:24 PM   #3
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
So can I use grep to strip that line from the file to a new file then use SED to strip the junk?

If so can anyone make me a little script please?
 
Old 01-23-2009, 02:52 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
So can I use grep to strip that line from the file to a new file then use SED to strip the junk?

If so can anyone make me a little script please?
Yes, you can use grep to burp that line through sed. And I'm sure there are lots of folks on here that CAN make you a script. The question is: are they willing to do work for you, for free?

A bash shell script tutorial can be found here http://www.freeos.com/guides/lsst/. Lots more tutorials are on Google, and you were provided with reference to the appropriate PHP function, which you had originally asked about.
 
Old 01-23-2009, 03:24 PM   #5
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Your right I have all the info I need so I'll give it a go thank you
 
Old 01-24-2009, 08:23 PM   #6
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
right i had a look but explode for php makes no sense to me.. so i need to ask for more help please
 
Old 01-26-2009, 11:04 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
right i had a look but explode for php makes no sense to me.. so i need to ask for more help please
What help do you need? Post what you've written so far, and what error(s) you're getting, and we can try to help.

You originally asked for PHP script, and the explode directive is fairly straightfoward. Take the variable:

$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";

...and explode it. The first field is the character you want to delimit the fields by, in this case, a space. Can be ANY character, though....

$pieces = explode(" ", $pizza);

...then print the value out. In this example, it's printing out the first variable (starts at zero).....

echo $pieces[0]; // piece1

That's it....loop through the array until you're done.

The BASH script tutorial I mentioned has ways of doing it via SED/AWK as well.
 
Old 01-26-2009, 11:19 AM   #8
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
well that's the thing i don't know php so i haven't written anything :\
 
Old 01-26-2009, 11:40 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
well that's the thing i don't know php so i haven't written anything :\
Ok, in your first post you mentioned PHP. I assumed that meant you had knowledge of it. Have you gone through the bash scripting tutorial? Looked at ANY of the thousands of example scripts you can find via Google?

Look at the docs for sed and awk.
 
Old 01-26-2009, 11:44 AM   #10
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
i have knowledge about php as in i can edit it very well i just can't make a whole entire script with it and yes i've looked at the docs for sed and awk but again makes no sence to me as i don't/can't make scripts

i'm sure it wouldn't take to long for someone to code me up a little script

Last edited by steve51184; 01-26-2009 at 11:45 AM.
 
Old 01-26-2009, 01:59 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
i have knowledge about php as in i can edit it very well i just can't make a whole entire script with it and yes i've looked at the docs for sed and awk but again makes no sence to me as i don't/can't make scripts

i'm sure it wouldn't take to long for someone to code me up a little script
You're right, it wouldn't take too long. But I doubt there's anyone here that will do work for you for free. You can hire a programmer or consultant, or look at any of the THOUSANDS of bash scripts and tutorials you can find through Google, and gain the knowledge yourself.
 
Old 01-26-2009, 05:04 PM   #12
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
but what is the point in this forum if no one will help? i thought it was it was here for?
 
Old 01-27-2009, 08:25 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
but what is the point in this forum if no one will help? i thought it was it was here for?
Yes...HELP. Post what scripts you've written, and what error(s) you get, and you will get help.

Ask someone to write you a script, because you don't want to do it, won't get you anything. You've been pointed to links giving you the information you need. This isn't the "free programmer forum", where you post a question and get back scripts.
 
Old 01-27-2009, 10:33 AM   #14
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by TB0ne View Post
Yes...HELP. Post what scripts you've written, and what error(s) you get, and you will get help.

Ask someone to write you a script, because you don't want to do it, won't get you anything. You've been pointed to links giving you the information you need. This isn't the "free programmer forum", where you post a question and get back scripts.
wow so rude!! i never said i don't want to do it i'd LOVE to be able to code but i can't and i've really really tried to but i just can't so don't say i won't when i can't!!!

anyway if this was just a bash script someone would've helped like they always do but cos it's php no one will

also you've replied to this topic 6 times over 4 days wouldn't it have been quicker for you to make it?
 
Old 01-27-2009, 10:45 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by steve51184 View Post
wow so rude!! i never said i don't want to do it i'd LOVE to be able to code but i can't and i've really really tried to but i just can't so don't say i won't when i can't!!!

anyway if this was just a bash script someone would've helped like they always do but cos it's php no one will

also you've replied to this topic 6 times over 4 days wouldn't it have been quicker for you to make it?
Not being rude to you, but being honest.

I've said from the very beginning that I'm not going to do your work for you, period. I doubt anyone will. If you can't do it, find someone else at your company who can. You've been given links to the PHP function that can do it easily, along with examples, and been pointed to the relevant commands (sed and awk), along with a bash scripting tutorial, but it doesn't appear that you've looked in to any of those resources, or done anything except ask people to write your scripts for you.

This can be done with bash or php..you pick. You say you've "really really tried". Post what you've done and the errors, and we can help you figure out what's wrong. Put some effort forth on your side, and you will get help. If you don't want to do anything but ask someone else to do your work for you, don't complain when they don't.

If you want help, post what you've done and the errors. If you want someone to write this for you, hire a consultant.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php script that reads content from text file adrianno2 Programming 3 07-21-2008 01:14 AM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 05:08 PM
PHP: limiting amount of text printed jme Programming 1 11-13-2004 08:13 AM
php script can not write text file lemotion Linux - Newbie 5 04-20-2004 10:14 PM
Display/Read line 'N' in a text file using script ganninu Linux - Newbie 2 10-13-2003 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:25 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration