Monday, May 23, 2011

Removing leading whitespace from file

Sometimes clients like to annoy me and send IPs in a "fancy" format with tabs and space and crap..ugh. I'm a one entry per line kind of guy. So I paste the entries into vim and I want to get rid of leading whitespace. This is the command in vim:


vim has sed-like regex recognition. This command tells vim to search (%s) for lines begining (^) with whitespace (\s), and include the rest of the whitespaces directly after the first one (*). Next, delete them (//). Now do this globally (g). By default, it will only match the first instance of the regex, g means "do this globally".

No comments:

Post a Comment