maybe, quizás, se cadra

maybe, quizás, se cadra

Mr. Ramos  //  that's me

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

cat file.csv | awk -F'[ "]+' '{print $4}' | sort | uniq -c | sort -n
(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)

Extract som elements from a file using a REGEXP

cat * | ruby -ne '$_.scan(/from (.*)./) { |m| puts m[0] }'
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(/Restricted user (.*) logged in to (.*) from/) { |m| print m[0],m[1],"\n" }'