reorder reorder columns in a file
doc generated from the script with gendoc
bash script, version=2.01

Synopsis

reorder [options] --fields=list [file]

Options

-h|--help
print short help and exit
-H|--Help
print full documentation and exit
-V|--version
print version and exit
-f|--fields
ordered list of comma-separated field(range)s
-s|--squeeze
squeeze off trailing empty fields
-t|--tab
column separator; default is the tab character
-u|--undefined
contents for undefined fields; default: empty
-i|--inplace
change file inplace

Description

reorder reorders the columns in a file (standard input by default) according to the list of comma-separated field numbers and/or field ranges given, where a field range is two numbers separated with a hyphen. Reverse ranges are allowed.

By default, columns are separated by tabs, unless a different separator is specified with the --tab option. Columns are counted starting at 1. Ranges of columns may be specified with hyphens.

Unavailable columns are replaced with empty ones or, if the --undefined option is used, with that options' argument. So if you specify the fifth column in a 2-column file, you end up with a 5-column file.

Output is written to standard output, unless the the --inplace option is used, which causes the output to be written to the original file.

Examples

Switch the second and third columns in a tab-separated file:

        reorder --fields=1,3,2 file

Reverse the three columns of a space-separated file:

        reorder -t' ' -f3-1 file

Move columns 7 through 9 after the last column in an 11-column tab-separated file:

        reorder -f1-6,10,11,7-9 file

Put two empty columns between the columns of a 2-column file:

        reorder -f1,3,4,2 file

Insert an empty column before the first in a file with a variable number of columns, with a maximum of 12, say:

        reorder -f20,1-12 file

This will result in a 13-column file with trailing empty fields!

The same, but replace undefined fields with '-' and remove trailing empty fields, and replace the original file with the output:

        reorder -siu- -f20,1-12 file

Author

Wybo Dekker

Copyright

Released under the GNU General Public License

Functions used:


handle_options

synopsis:
handle_options "$@"
description:
handle the options.
globals used:
Myname Version
globals  set:
args