CLI Usefullness
For the past year and a half I’ve been doing developement in a linux based enviroment, these tools and particularly these commands have become used frequently. If anyone has something useful, post it up!
Mercurial is a cross-platform, distributed revision control tool for software developers.
Easy way to view most recent changes:
Command: hg export tip | colordiff | less -R
Useful for: Quick code reviews, or just to peek at what you’ve recently done
Manipulating text files:
SED: (stream editor) is a Unix utility that (a) parses text files and (b) implements a programming language which can apply textual transformations to such files.
Command: sed ’s/\t/”,”/g;s/^/”/;s/$/”/;s/\n//g’ > filename.csv
In action: mysql -uuser -ppass DBNAME -e “SELECT foo FROM bar WHERE baz = ‘world’” | sed .. > output.csv
Explanation:
- “s/\t/”,”/g;” – Search for tabs, replace with commas
- “s/$/”/;” – Replace last of line with quote
- “s/\n//g” – Remove newlines
Useful for: This is specifically used for converting MySQL results to csv. I build lots of mailing lists for my employer.
AWK: is a programming language that is designed for processing text-based data, either in files or data streams, and was created at Bell Labs in the 1970s
Command: awk ‘BEGIN {OFS=”|” FS=”|”}; {print $1, $3, $5}’ file.csv
Explanation:
- OFS – Output field separator
- FS – Field separator
- Printing fields 1, 3, and 5
Useful For: Pulling text out of delimited list and re-organizing the data, quickly and gui-free
