4 ms·
alias awk1="awk {print $1;}" Counting to 9, inclusive, is left as an exercise for the reader.
by fragmede 5y ago
alias awk1="awk {print $1;}"
Counting to 9, inclusive, is left as an exercise for the reader.
- boring_twenties 5y agoawp () { local a a=() while [[ -z ${1:#-*} ]] do a=($a $1) shift done local n n=$1 shift awk $a '{print $'$n'}' $* }
- sillysaurusx 5y agoAmusingly, I apparently added these to scrap https://github.com/shawwn/scrap https://github.com/shawwn/scrap many years ago. I named them 1st, 2nd, 3rd, and 4th. So I guess I never needed to count to 5, but I'm still two ahead of Valve. https://www.youtube.com/watch?v=jpw2ebhTSKs https://www.youtube.com/watch?v=jpw2ebhTSKs EDIT: Actually, I'd never committed 4th. It was just sitting here in my local scrap. So I guess I counted to three, realized at some later date I needed four, copied 3rd to 4th, then never committed. Oh. Apparently I also have 'nth', which was exactly what I wanted: > echo a b c d | nth 0 3 a d The solution I came up with at the time: #!/bin/bash c="" for n in "$@" do n=$((n+1)) args="${args}${c}\$$n" c=', ' done awk "{ print ${args}; }" Nowadays I'd write it like: awk "{ print $(echo "$@" | args math '1+{}' | replace '^' '$' | trim | joinlines ', '); }" But I admit both are equally cryptic, and the former might even be more readable.