find an expression, but replace another..

Tool for Search and Replace across multiple files.
FelixAtagong
Posts: 2
Joined: Wed Jul 20, 2011 6:43 pm

find an expression, but replace another..

Post by FelixAtagong »

My blog has about a thousand html files in monthly directories over about 5 years, so about 60 directories.
I would like to add a no-index tag in the head section for obsolete entries, this is in about 180 posts out of a 1000.

Basically what I want to do: if the html file contains the line
'posted in: category'
(located somewhere in the middle of the document), I would like to add a
<meta name="robots" content="noindex" />
tag in the head section.

Is this possible (without breaking directory structure etc...)?
User avatar
Fool4UAnyway

Re: find an expression, but replace another..

Post by Fool4UAnyway »

Yes, this should be possible, as far as I can tell.

You could just look for some specifier near (just before or after) the point you want to insert (or replace) the "noindex" tag, then allow anything else to match and then require the "posted in" part and capture the complete match from the targeted point of insertion.

You would have to check the ". dot matches newline" option for this.

You could then insert the "robots" tag and re-place the text following it in the Replace field.

If you specified a prefix, you would have to capture that as well, and re-place it, too.

Just an example, as I am not that well into HTML.

Find:
(head>)(<.*posted in: category)

Replace:
$1<meta name="robots" content="noindex" />$2

An alternative way is to first find all the files containing the "posted in" part, mark these files, and then perform a second run on only those files search just insert the "noindex" tag at the targeted location.
FelixAtagong
Posts: 2
Joined: Wed Jul 20, 2011 6:43 pm

Re: find an expression, but replace another..

Post by FelixAtagong »

Marvellous, I didn't see the 'in marked files' tickbox and was trying to find out a way how to do this! :oops:
Post Reply