Tag Archives: regex
Removing leading whitespace in file with perl.
Do you ever have code with such poor formatting that you just need to start over? This will let you remove all leading whitespace from every line in the file. I’ve found it handy every now and then. perl -i -pe's/^\s+//' file.c
My most used VIM regular expressions.
Delete all lines in a file except those that start with “#”. :g/^[^#].*$/d Text search/replace. Transform line ‘wget http://gnucom.cc/some_backup.tar.gz’ into ‘/scripts/restorepkg some_backup.tar.gz’. This one is helpful for cPanel administrators. :%s/wget http:.*\//\/scripts\/restorepkg /g Add something to the end of every line of a file. :%s/$/something/g Add something to the beginning of every line of a file. [...]
My most used Perl regular expressions.