select_columns

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 02 March 2009
Index Return to Main Contents

 

NAME

select_columns - select named columns from CSV stream

 

SYNOPSIS

edrc/lib/select_columns -h

select_columns "field_separator" "column_list"

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

filter to select named columns that are separated by a field separator from stdin and print the selected columns to stdout. The first row of the data stream must contain the row header. Columns that do not exist, are printed as empty columns.

 

OPTIONS

-h
usage message.

"field_separator"
field separator.

"column_list"
separated list of columns to be printed from the CSV stream from stdin.

 

ENVIRONMENT

-

 

EXIT STATUS

0
no error.

4
usage displayed.

 

FILES

-

 

EXAMPLES

1) select certain columns form CSV data

The following CSV data received via pipe

  cat<<EOM | select_columns ";" "CNT;ZIP;CITY"
  ZIP;CITY;STATE;CNT;COUNTRY
  93117;Goleta;CA;USA;United States of America
  8222;Beringen;SH;CH;Switzerland
  8005;Cape Town;WC;RSA;South Africa
  EOM

results in the output:

  CNT;ZIP;CITY;
  USA;93117;Goleta;
  CH;8222;Beringen;
  RSA;8222;Cape Town;

2) print selected columns of CSV data as formatted list

The columns CNT, ZIP and CITY of the CSV data are selected using the select_columns command and then formatted to a list using the print_list(3) command

  cat<<EOM | select_columns ";" "CNT;ZIP;CITY" | print_list
  ZIP;CITY;STATE;CNT;COUNTRY
  93117;Goleta;CA;USA;United States of America
  8222;Beringen;SH;CH;Switzerland
  8005;Cape Town;WC;RSA;South Africa
  EOM


what will result in the output:


  CNT  ZIP    CITY
  ---  -----  ---------
  USA  93117  Goleta
  CH    8222  Beringen
  RSA   8005  Cape Town
  (3)

 

SEE ALSO

edrcintro(1), csv(3), csvcat(3), print_header(3), print_index(3), print_list(3)

 

NOTES

The four commands print_header(3), print_list(3), select_columns(3) and print_index(3) provide the functionality to efficiently produce ASCII reports having an identical look.

 

BUGS

-

 

AUTHOR

select_columns was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2009 Christian Walther

This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 00:14:23 GMT, March 08, 2025