Oneliners
Why?
Commandline is quite helpful in many ways in my everyday life. Some simple scripts (and combination of program output) can simplify my work. This page is about to list some of this info.
Add new files to Subversion
svn status | awk ‘/^\?/{print $2}’ | xargs svn add
Get the list of all the installed GEMS (Ruby Packages)
gem list --local --no-details | grep '^\w' | cut -f 1 -d ' '
Extract values from a CSV column and summarize the values
(Note: using cat for just one file just does not make any sense, but this syntax is easy understandeable, and the rest of the comandline could be copied and pasted and reused in other places)cat file.csv | awk -F'[ "]+' '{print $4}' | sort | uniq -c | sort -n
Extract som elements from a file using a REGEXP
This could be also achieved by using 'grep -o', but I use this one linner to more complex queries when I want to extract several values on a single oneliner: cat * | ruby -ne '$_.scan(/from (.*)./) { |m| puts m[0] }'
cat * | ruby -ne '$_.scan(/Restricted user (.*) logged in to (.*) from/) { |m| print m[0],m[1],"\n" }'
