Saturday, February 27, 2010

Search and replace where you need it.

Being able to search and replace text, regardless of how it is stored is a humoungous time saver so I thought I'd share a couple methods I use.

SSH BASH perl one line search replace
I usually do my file editing & programming work via SSH with PuTTY so a command line search and replace is really handy especially when large amount of files are involved. Here is an example of altering one file . . .

perl -pi -e "s/old text/new text/gi;" filename.txt

Remove the g to only replace the 1st occurrence of old text. Remove the i to make it case sensitive.

Of course replacing the example filename "filename.txt" with files you actually need to alter, for example, change all mentions of oldsite to newsite in all .php files in the current directory


perl -pi -e "s/oldsite/newsitet/gi;" *.php

Or, to do every php file even ones in sub directories...

perl -p -i -e 's/oldsite/newsite/g' `find ./ -name *.php`

Of course perl and BASH being what they are, there are likely 30 different ways to do th same thing, but thus far this one has worked just fine. It is also incredibly fast

What I recommend is copy the files you plan to do search replaces on to a new temporary directory, and test your search replace commands to ensure they have no undesired consequences.


MySQL query to search replace.

Often I need to quickly and accurately change text in a MySQL database.  Here is a MySQL query that does exactly that.

update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]'); 

Using PHPMyAdmin it is pretty easy to make a copy of the table and use it for test runs of search replace queries. Depending on the application a search replace done incorrectly could spell disaster so never ever do search replaces on a live and in use mysql table.

As an example, I wind up moving a lot of Wordpress websites in my freelance work, typically from my own development area on my webserver, to the new account my client has created for their live Wordpress site. This MySQL query can be modified for your use when moving a Wordpress site.

update wp_options set `option_value` = replace(`option_value`, 'URL TO MY WORDPRESS DEV', 'URL TO THE LIVE WORDPRESS SITE');

Other methods.

While I live in a SSH shell most of my computing day I am on a Windows workstation. and occasionally do need to search replace text files on my own hard drive. Thus far I don't have an elegant solution but using Windows file search, with the content search option I can get a nice tidy list of files that need the edit. I can then select as many as I need (or as many as my computer can handle) and right click to open with Notepad++ . From there I can do a search replace on all open documents and save them in a couple of clicks.

Software mentioned in the article
PuTTY :  http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Notepad ++ : http://notepad-plus.sourceforge.net/

Thursday, February 18, 2010

Microsoft Yahoo merger

After Microsoft's failed attempt to simply buy Yahoo one would think they'd realize, or at least learn to be content with their place in the search engine pecking order, which  is 2nd, or 3rd depending on where you look, but no. In classic more money than brains corporate fashion they'll be paying Yahoo to set aside it's own search engine and run a co-branded version of Microsoft's bing.  

For myself, or rather my websites this may be a good thing. Currently while I get much less traffic from Bing than Google, Bing users are roughly 20% more likely to convert, so I'm hoping that trend holds true with Yahoo users.. or will they be Ya-Bing users..

Still in the big scheme of things, this stinks of desperation. A stark example of corporate mentality, profit at any cost, and if profit is unobtainable, pay to chip away at the top competitor, incurring a loss to do so.  Maybe it's just time to throw in the towel and stick to your primary niche products?

Monday, February 15, 2010

ISS almost finished

No tech talk today, well not internet related anyway. Wanted to talk about ISS, you know the almost
400 metric tons of materials and technology that has been shot into orbit and assembled, the international space station. Well, it is pretty close to completed.

I remember 12 years ago when the first parts were launched thinking if all the countries involved can
set aside petty bickering, focus on the science and work together the world as a whole might just be
able to pull it off, but I had some serious doubts. 12 years is a long time, and it seemed inevitable
that something somewhere somehow would mess it up.  Glad to say I was wrong.

So now that the last major components are together. With only the white picket fence to paint and
the curtains to hang, the world now has a piece of orbital real estate to make use of, and in many
ways that is a tremendous accomplishment.

Of course it's a victorious time for NASA, all the astronauts, flight crews, advisers, manufacturers and
everyone else that had a direct hand in the assembly of ISS, but to me, it is also a victory for humankind.

Proof that together, we can achieve common goals as a unified global work force, and that gives me
something rarely found, hope.

Friday, February 12, 2010

Search engines hate my site !

Ok, not actually my site, but some clients I have worked with in the past seemed convinced the cigar smoking bigwigs at certain search engine companies had a personal vendetta against them. I can apreciate the desire to increase traffic to your website, I have my own as well that I'd like to see improved (and it is gradually) but a word of caution. In the case of SEO, or more specifically on site / page SEO, too much is really too much.

In other words, sometimes in an effort to tweak your site to be more search engine freindly you wind up over optimizing it, or worse, triggering penalties by perceived black hat SEO tactics.

There is no silver bullet or point and click method that results in instant search engine success. Anyone trying to sell you one should probably be slapped, or at least ignored. Effective SEO is much more about knowing what not to do, than it it is stuffing in the latest whizzbang method into your pages.

To me, that is as it should be. Websites that are created poorly and look like thousands of other sites should not outshine sites where the webmaster has worked hard to provide quality content that is unique.

If you've been at this a while, you are probably tired of reading "content is king!" so that is my only mention of it, but how about "legible text is paramount!" or "the importance of predominantly unique and grammatically correct authoring should not be underestimated". Ok, that last one was a bit long, but you get my drift.

Something I suggest.. open a copy or notepad or whatever text editor you use. Browse to your home page, hit crtl+A key to select all text then ctrl+C top copy it. Now paste that into notepad. Reading it, if it isn't obvious what the site is about within the first few sentences you should probably consider changing your layout. This is essentially what Googlebot and other search engines see, and what they use to attempt to categorize your site.

Note, when I say "consider changing your layout" I don't necessarily mean changing the look or placement of your textual content. The goal is to get the unique and relevant text closer to the top when viewing the HTML source of your pages. Using CSS positioning, that text can be displayed wherever you like.

Another shoot yourself in the foot tactic I often find is large amounts of inline styles and java script within the HEAD tags of HTML pages. Whenever possible these should be moved and referenced from external files, like style.css or functions.js Search engine bots really don't care about how the page is styled and typically don't run java script, so why make them wade through it. Again, getting your unique and relevant text closer to the opening BODY tag.

I've just realized I probably have a hundred other SEO blunders to cover, but the last not so good idea I'll mention here is the overstuffed deceptively flattering sitemap.xml approach...

Overstuffed.. It is not necessary to mention every URL of your site in the sitemap.xml If your site has a dozoen or so pages, then it's likely fine, but hundreds? Probably too many, thousands? Definitely too many.

Just ensure your sitemap.xml file has your most important sections of your website possibly /blog , /forums, /contact, /about etc. You do not need every URL. If your site has reasonable navigation the search engine spiders can follow the links to the remainder of your site.

Deceptively flattering.. I may have mentioned this before, but all too often I run across sitemap.xml files where every URL has an importance of 1.0 and or is updated daily. Really!? C'mon be honest. If /contact is updated daily then you must be an under cover agent or maybe a paid assasin.

The point is, be realistic. /forum likely does get new content every day, /blog might be daily, weekly .. or if you are lazy like me monthly. So yes, be honest and realistic when assigning importance and update frequency in your sitemaps.