Thursday, June 21, 2012

Brute force using VIM

I was just presented with a situation where about 60 html files were generated and some of them contained duplicate entries that needed to be removed. We couldn't go back and re-generate because some of the verbiage on the pages had been tweaked already. I started looking into sed to see if it would help, but it apparently doesn't shine at finding duplicates and removing them. So it looked like the only way was to brute force edit each page ... blah!

But wait ... VIM can make even the most laborious task seem trivial if you know a few key concepts.

So I decided to buffer all the *.html files and tell vim to find a specific string in each of them. The string was the html class of the menu.

vim +/search\ string *.html

Now I have all the files open and I simply need to review each one for the dupes. So for each file, I simply pressed "n" to find the next occurrence. If the dupe was present, I executed


move down 7 lines, start selection, move down 6 lines then delete the selection. Then I simply saved the file and deleted it from the buffer and on to next file.

I probably could have used a macro but that would have taken longer to learn than the 10 minutes it took to edit the files. So I'll put that at the top of my reading list.

Knowing your toolset can make the most laborious task seem trivial. Continuous learning, not just the language you use but the tools that support your efforts, is the key here.

Sunday, May 6, 2012

Thursday, May 3, 2012

Accessing command line from within VIM

This has proven pretty handy and wanted to document so I wouldn't forget.

To suspend VIM and reveal the current command line:

"Ctrl+Z" then run your commands as normal and then "fg" to return to VIM.

This will also execute the command and wait for you to hit enter before proceeding:


Thursday, April 26, 2012

Faster Terminal Logins

That slowness when you start Terminal? It's parsing through all your system logs to figure out when the last log-in occured. Speed up your terminal with

touch ~/.hushlogin


Sunday, February 26, 2012

Using tmux

Just started using GNU Screen recently and it's definitely a productivity booster. Saw a post comparing screen and tmux today and now I think tmux might be the way to go. Screen doesn't appear to be under active development and tmux has a few features screen lacks (vertical split) ... anyway here are a couple of articles I found helpful during the switch.

Tuesday, January 24, 2012

Real leaders follow through on their promises ...

Very few times in history have leaders actually followed through on what they promised. Government Transparency was one of those promises and this simple serves to hide what our elected officials are actually doing. This generally leads to disenfranchised voters that simply ignore the process in future elections. I will vote in the next election and I will vote for Ron Paul ... even if I have to write his name on the ballot myself.

Read the following article from Salon ...

Rules of American justice: a tale of three cases

As EFF’s Trevor Timm put it yesterday: this is the “6th time under Obama someone is charged with Espionage for leaking to a journalist. Before Obama: only 3 cases in history.” This is all accomplished by characterizing disclosures in American newspapers about America’s wrongdoing as “aiding the enemy” (the alleged enemy being informed is Al Qaeda, but the actual concern is that the American people learn what their government is doing). As The New York Times‘ Charlie Savage wrote this morning, Obama has brought “more such cases than all previous presidents combined,” and by doing so, has won the admiration of the CIA and other intelligence agencies which, above all else, loathe transparency (which happens to be the value that Obama vowed to provide more of than any President in history).