#!/bin/bash ## arr -- much like the Mantes arrange-command -- by Eugene Reimer 2001-oct; ## obsoletes several of my earlier scripts: dbl, colswap; ## ## USAGE EXAMPLES: ## arr 2 1 --a filter to swap columns, for a 2-column file ## arr 1 1 --a filter to "double" a 1-column file ## arr 3 2 1 --a filter to column-reverse a 3-column file ## LINECNT=$(wc $1 |arr 1) --get number-of-lines in file ## ## Copyright © 2001,2004 Eugene Reimer; can be used, modified, copied, and distributed or sold under the terms of either the LGPL or the GPL (your choice); ## see http://www.gnu.org/licenses for the details of these terms. [ $# -eq 0 ] && { echo "usage: arr column-nbrs"; exit; } s='{print $'"$1"; shift for x do s="$s"' " "' if [[ $x == [0-9]* ]]; then s="$s"' $'"$x" else s="$s \"$x\"" fi done s="$s}" ##echo "awk $s"; read ##debug awk "$s" exit 2004-feb: added support for non-numeric literals between column-nbrs; literals & columns are separated by TAB-chars