LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 01-27-2009, 10:51 AM   #16
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30

but again you really don't seem to understand i can't do this! some people can some can't

also i've looked at explode and can't figure it out nor do i think it's what i need :\
 
Old 01-27-2009, 10:56 AM   #17
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
Quote:
Originally Posted by steve51184 View Post
but again you really don't seem to understand i can't do this! some people can some can't

also i've looked at explode and can't figure it out nor do i think it's what i need :\

No, I do understand, but you're missing several points. Let me be more clear:

1. PHP is one option. I only mentioned it because YOU started the thread, by bringing up PHP. I gave you the link to the resource and example on how to do it via PHP.

2. BASH script is the second option. I gave you the commands to use (sed and awk), which have ample documentation, both through man pages and thousands of examples that can be easily found through Google.

3. If you can't do it, why do you not think the solutions given to you are what you need?

4. If you can't do it HIRE SOMEONE WHO CAN OR LET SOMEONE ELSE DO IT.

Google for "linux sed search replace". You will find lots of information with sample scripts that you can use. If that's too hard, again....HIRE SOMEONE.
 
Old 01-27-2009, 11:27 AM   #18
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
getting to work now will post what i have soon
 
Old 01-27-2009, 11:41 AM   #19
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
right now i'm getting somewhere but i'm having trouble so i'll post what i have:

this strips the "RewriteCond %{REMOTE_ADDR}" line from my file and writes it to a new file
Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/test.txt > /home2/list.txt

this removes the "RewriteCond %{REMOTE_ADDR} (" part
Code:
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/list.txt

now i'm trying to use sed and the same command above to remove all the \ but i get this error:

Quote:
# sed -i 's/\//g' /home2/list.txt
sed: -e expression #1, char 6: unterminated `s' command

and i'm also trying to remove )$ at the end of the file but it's not removing it or giving me an error here's the command:

Code:
sed -i 's/)$//g' /home2/list.txt
 
Old 01-27-2009, 12:16 PM   #20
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
Quote:
Originally Posted by steve51184 View Post
right now i'm getting somewhere but i'm having trouble so i'll post what i have:

this strips the "RewriteCond %{REMOTE_ADDR}" line from my file and writes it to a new file
Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/test.txt > /home2/list.txt

this removes the "RewriteCond %{REMOTE_ADDR} (" part
Code:
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/list.txt

now i'm trying to use sed and the same command above to remove all the \ but i get this error:




and i'm also trying to remove )$ at the end of the file but it's not removing it or giving me an error here's the command:

Code:
sed -i 's/)$//g' /home2/list.txt
This is where you should have been, 4 days ago.

Quote:
sed -i 's/\//g' /home2/list.txt
To get 'special characters' (like the \, /, |, etc.), to go through, try escaping them with a backslash, like:

Code:
sed 's/\\//g' /home2/list.txt
You don't need the "-i" for this..that means case-insensitive, and since you're only doing a special character, you don't need it. Putting a leading backslash will make sed treat the next character as JUST a character, rather than a 'control' character, which does something special.

This should also work for this:

Code:
sed 's/\)\$//g' /home2/list.txt

You can also (if you want to), string your sed's together on one line, like this:

Code:
cat <filename> | sed <whatever> | sed <whatever> | sed <whatever> > output.file
 
Old 01-27-2009, 12:30 PM   #21
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
if i don't put a -i in this command it just outputs on the screen and not to a file

Code:
sed 's/\\//g' /home2/list.txt
also i can't get the second command to work:

Quote:
# sed 's/\)\$//g' /home2/list.txt
sed: -e expression #1, char 9: Unmatched ) or \)
 
Old 01-27-2009, 12:52 PM   #22
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
right i've almost done it with this so far:

Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/test.txt > /home2/list.txt
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/list.txt
sed -i 's/\\//g' /home2/list.txt
tr -d \\n < list.txt | tr \| \\n | sort > list2.txt && mv list2.txt list.txt
the only thing i need to do is strip the )$ bit
 
Old 01-27-2009, 01:04 PM   #23
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
nm i've done it with the following:

Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/test.txt > /home2/list.txt
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/list.txt
sed -i 's/\\//g' /home2/list.txt
sed -i 's/)//g' /home2/list.txt
sed -i 's/\$//g' /home2/list.txt
tr -d \\n < list.txt | tr \| \\n | sort > list2.txt && mv list2.txt list.txt
thank you very much for helping/forcing me to do this i really had fun doing it and will think/look harder next time
 
Old 01-27-2009, 01:06 PM   #24
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
Quote:
Originally Posted by steve51184 View Post
also i can't get the second command to work:

# sed 's/\)\$//g' /home2/list.txt
sed: -e expression #1, char 9: Unmatched ) or \)
Hmm...not at a machine where I can test this, but it's probably got to do something with the backslashes. Sed can be picky...try:

Code:
sed 's/\\)\$//g' /home2/list.txt
and see if that gets it.
 
Old 01-27-2009, 01:10 PM   #25
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by TB0ne View Post
Hmm...not at a machine where I can test this, but it's probably got to do something with the backslashes. Sed can be picky...try:

Code:
sed 's/\\)\$//g' /home2/list.txt
and see if that gets it.
read my last post:

http://www.linuxquestions.org/questi...54#post3423054
 
Old 01-27-2009, 02:18 PM   #26
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
seems like i forgot i was wanting this to be a html page so i edited it to display properly:

Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/.htaccess > /home2/test.html
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/test.html
sed -i 's/\\//g' /home2/test.html
sed -i 's/)//g' /home2/test.html
sed -i 's/\$//g' /home2/test.html
sed -i 's/|/<br>/g' /home2/test.html
but i want to include other formatting within the file so is there a way with grep/sed/awk to include a line of code at the start/end of a file?

i've searched google but i'm not getting anything other then weird links
 
Old 01-27-2009, 02:25 PM   #27
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
Quote:
Originally Posted by steve51184 View Post
seems like i forgot i was wanting this to be a html page so i edited it to display properly:

Code:
grep -i "RewriteCond %{REMOTE_ADDR}" /home2/.htaccess > /home2/test.html
sed -i 's/RewriteCond %{REMOTE_ADDR} (//g' /home2/test.html
sed -i 's/\\//g' /home2/test.html
sed -i 's/)//g' /home2/test.html
sed -i 's/\$//g' /home2/test.html
sed -i 's/|/<br>/g' /home2/test.html
but i want to include other formatting within the file so is there a way with grep/sed/awk to include a line of code at the start/end of a file?

i've searched google but i'm not getting anything other then weird links
You can do it with a bit of simple 'cheating'. For example, the '>' character. One of them will write to a file (overwriting what ever is there), but if you put two, you will append text to it. So you could do:

Code:
echo "Beginning line of my report..." > output.file
<your shell script here> >> output.file 
echo "Ending line of my report..." >> output.file
First line puts text in the new output file. Second line is the shell script you just wrote, which will put it's output after the first line you just wrote. Third line puts the 'ending' on.

There's lots of different ways to do it, that's VERY quick, and VERY dirty.

You must have been posting yours, when I was posting mine.
 
Old 01-27-2009, 02:29 PM   #28
steve51184
Member
 
Registered: Dec 2006
Posts: 372

Original Poster
Rep: Reputation: 30
wow that's an amazing trick and i had not idea about the double > thank you very much
 
  


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 03:16 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