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

后端 未结 8 1994
春和景丽
春和景丽 2020-11-28 03:29

Let\'s say that during your workday you repeatedly encounter the following form of columnized output from some command in bash (in my case from executing svn st

8条回答
  •  感动是毒
    2020-11-28 04:14

    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
    

提交回复
热议问题