#!/bin/bash if test $# -ne 2; then echo 1&>&2 "Usage rename.sh inputfile outputfile" exit 1 fi IN=$1 OUT=$2 set -x awk 'BEGIN {FS=" ";OFS=" "} {ss=$1; $1=$2; $2=ss; print $0; }' $IN >$OUT |
This script can be used to swap the first and second column seperated by FS which is space here, and you can specify the OFS which is the new delimeter of the swapped file.
In print, you can also use ‘%s’ to output in your wanted format.
such like
awk '{printf "%6s %10s" $2, $1}' file
much like this.