Over the weekend I started studying Perl and quickly realized I was going to be better off if I reviewed regular expressions before I got too far into things. I went back and found my copy of “Mastering Regular Expressions” and dove right in. Now, maybe its just me, but I find that I really enjoy the problem solving aspect of regular expressions. I thought it might be fun to put up a regular challenge on the blog that needs to be solved via regular expressions.
So, I figure I’d start off with one that caught me today. Here is the situation:
You’ve got a regular text file filled with usernames. You want to be able to read this file into a program to populate an array, but there are random blank lines throughout the file. What regex would you use to find and remove all empty lines in the file?
For consistency sake, I’ve populated just such a file and made it available here.
Rules: Use any tool you want (perl, sed, vim, etc) The file must contain all original usernames (total of 15), one per line, with no blank lines start to finish. Please share your solution in the comments!





