#!/bin/sed -f
# swap.sed
# sed: swap first two fields in a line of tab-delimited fields
# Run this program with the command
#   sed -f swap.sed swap.txt
# where swap.txt is an input file with tab-delimited fields
s/^\([^ ]*\)    \([^    ]*\)/\2 \1/
#   Note - each blank is actually a single hard tab "\t"
#       s/^\([^\t]*\)\t\([^\t]*\)/\2\t\1/

Example 3: Example 1 in sed.

Back to Article