bash: shortest way to get n-th column of output bash: shortest way to get n-th column of output bash bash

bash: shortest way to get n-th column of output


You can use cut to access the second field:

cut -f2

Edit:Sorry, didn't realise that SVN doesn't use tabs in its output, so that's a bit useless. You can tailor cut to the output but it's a bit fragile - something like cut -c 10- would work, but the exact value will depend on your setup.

Another option is something like: sed 's/.\s\+//'


To accomplish the same thing as:

svn st | awk '{print $2}' | xargs rm

using only bash you can use:

svn st | while read a b; do rm "$b"; done

Granted, it's not shorter, but it's a bit more efficient and it handles whitespace in your filenames correctly.


I found myself in the same situation and ended up adding these aliases to my .profile file:

alias c1="awk '{print \$1}'"alias c2="awk '{print \$2}'"alias c3="awk '{print \$3}'"alias c4="awk '{print \$4}'"alias c5="awk '{print \$5}'"alias c6="awk '{print \$6}'"alias c7="awk '{print \$7}'"alias c8="awk '{print \$8}'"alias c9="awk '{print \$9}'"

Which allows me to write things like this:

svn st | c2 | xargs rm