csv Code
Convert a csv file to one easily field readable by Unix shell scripts
Brought to you by:
benalt613
| File | Date | Author | Commit |
|---|---|---|---|
| LICENSE | 2016-10-26 |
|
[96a1ad] Initial commit |
| README | 2016-11-12 |
|
[d6b627] Add files via upload |
| README.md | 2016-10-26 |
|
[96a1ad] Initial commit |
| csv.awk | 2017-03-18 |
|
[61aee0] Handled bug where field is blank with "" |
| csv.bash | 2017-03-18 |
|
[61aee0] Handled bug where field is blank with "" |
| csv.ksh | 2017-03-18 |
|
[61aee0] Handled bug where field is blank with "" |
SCRIPTS:
csv.awk, csv.ksh, csv.bash
AUTHOR:
Ben Altman (csv.feedback.benalt at xoxy.net)
DESCRIPTION:
csv.awk, csv.bash and csv.ksh are awk, bash and ksh scripts
to export MS Excel style csv files into files with other
delimiters. They handle quoted and unquoted fields as well
as multi-line fields. The csv delimiter is a comma by
default but can be specified to be a regular expression.
Though if a pipe is specified for a csv input file field
separator, I escape it to "[|]" assuming a literal pipe is
intended rather than the regex meaning "or". The output
delimiter can be specified to be any string (pipe by
default) as can be the new-line for multi-line fields ("\n"
characters by default). The output can be in a format that
can be easily be used as input to shell scripts using the
read command.
USAGE:
csv.awk [options] [csv_file(s)]
Options:
fs=csv_file_field_separator (default is comma)
ofs=output_field_separator (default is pipe)
nl=multi-line_field_separator (default is "\n")
csv.ksh [options] [csv_file(s)]
csv.bash [options] [csv_file(s)]
Options:
-i csv_file_field_separator (default is comma)
-o output_field_separator (default is pipe)
-n multiline_field_separator (default is "\n")
-l or -m can be used in place of -n
CSV files can be mentioned explicitely or scripts can have
data redirected to them via pipe or stdin.
EXAMPLES:
To convert a csv file to "@" delimitted format with
multi-line fields merged using the space char to be read in
via a while loop in bash:
csv.awk OFS=@ nl=" " testfile.csv |
while IFS=@ read -a field; do
Convert a csv file to a pipe delimitted file:
csv.bash < testfile.csv > testfile.txt
or
csv.ksh testfile.csv > testfile.txt
or explicitly, joining multi-line fields with a space:
csv.bash -o\| -n" " testfile.txt