Link to home
Start Free TrialLog in
Avatar of canfote5
canfote5

asked on

Regular Expression, delete everything that is after or (and) before a text on a line

so...I have this text

12 look mywebsite.com/image/dark.jpg 12 visits
13 look mywebsite.com/img/icon/1.jpg 2 visits 1 out
14 look 1 out mywebsite123.com/image/dark.jpg 1 visit 2 out

My question: I need 3 regular expressions.
1. to delete everything that is after ( lets say ) mywebsite.com
2. to delete everything that is before ( lets say ) mywebsie.com
3. to delete what is before and after ( lets say ) mywebsite.com

Thanks for the help
Avatar of neilfw
neilfw
Flag of United Kingdom of Great Britain and Northern Ireland image

assuming the above text is in a file called a.log and needs to be placed in a file b.log, and that based on your description you want the FQDN from that log

sed -e 's#^.* \([a-zA-Z0-9.-]*\)/.*$#\1#' a.log > b.log

Modify the data in \([XXX]\) to adjust the lookup if your data varied from the normal charachters accepted in a FQDN.  

ASKER CERTIFIED SOLUTION
Avatar of LeeeRussell
LeeeRussell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of canfote5
canfote5

ASKER

hi,
I;m in complete darkness here :)
I'm using the free program delete lines from ab-tools.com . I just need to enter the string in that program. He outputs a new file with the results , etc.
Can you please past the regular expressions solutions for every questions...like
1. this is he string to use
2. this is the string to use
3. this is the string to use
If you require a more detailed explanation you will have to supply a bit more information, such as:

The language you are using (if this is a script).
How the input text is provided (text file, input stream, etc.)
And where you want the output to go (text file, etc.)
it is a log, and it is only normal text , like I shod you above. The text is in a txt file.
I do not need to replace enything, just delete everything after or before what I want
I couldn't find the software you talked of ("delete lines"?) on the website you gave.  If without knowing what the software requires it will be quite difficult to give an answer.

The expressions I posted before would work in something like notepad++ if you opened the log file there, used the regular expression search in the find and replace dialog (radio buttons at bottom of this dialog), and then enter the searches I provided.

The first poster showed you how to use a piece of software called sed (available on unix systems) to do the find and replace.

Basically different software will represent regular expressions slightly differently, so it is important to know how the software you are using represents them before I could give a definite answer.
http://www.ab-tools.com/English/software/deletelines/

this is the software, it is small, you can test it.
Right, I've looked at the software you've suggested.  As far as I understand it, this software will delete the *whole* line when it finds the line it wants.  You can search for lines to delete using a regular expression, but it will then delete the whole line.  Is this what you require?  

From your initial question I had assumed that you wanted to delete the text before or after mywebsite.com for each individual line.  Is this correct?  Or do you want every subsequent line deleted before or after it has found mywebsite.com?
:(
I thought that with a regular expression I can just delete what is before mywebsite.com on every line.
What shod I use then?
I have macromedia dreamweawer cs4. I see that when I ctrl+f it shows me that I can search for a regular expression too. Will that help? What shod I use?
It may be best if you used something like notepad++ as I don't know Dreamweaver (http://notepad-plus.sourceforge.net/uk/site.htm).  Notepad++ is free and is a very good text editor as well.

If you download this, you should be able to open the log file you have, and then use the find and replace dialog and the original search strings I provided for you.

The find and replace dialog has a set of radio buttons at the bottom, and you will need to select the regular expression one.  The copy and paste the search and replace strings I provided you with.
OK, I download it, install it, but it does not work. The regular expressions that you provided just deletes all the line.
The expression I provided should select all the line, but are you saying that when you press replace it then deletes the whole line?  Have you put    \1    in the replace field?

If you have left the replace field empty then it would delete the whole line?