Database Reference
In-Depth Information
--iformat= format , --oformat= format , --format= format
Specify an input format, an output format, or both. This option is shorthand for
setting the quote and delimiter values. --iformat=csv sets the input quote and
delimiter characters to double quote and comma. --iformat=tab sets them to “no
quotes” and tab.
--ilabels , --olabels , --labels
Expect an initial line of column labels for input, write an initial line of labels for
output, or both. If you request labels for the output but do not read labels from the
input, cvt_file.pl uses column labels of c1 , c2 , and so forth.
cvt_file.pl assumes the same default file format as LOAD DATA and SELECT INTO OUT
FILE , that is, tab-delimited lines terminated by linefeeds.
cvt_file.pl is located in the transfer directory of the recipes distribution. If you expect
to use it regularly, install it in some directory that's listed in your search path so that you
can invoke it from anywhere. Much of the source for the script is similar to
mysql_to_text.pl , so rather than showing the code and discussing how it works, I'll just
give some examples that illustrate how to use it:
• Read a file in CSV format with CRLF line termination, and write tab-delimited
output with linefeed termination:
% cvt_file.pl --iformat=csv --ieol="\r\n" --oformat=tab --oeol="\n" \
data.txt > tmp.txt
• Read and write CSV format, converting CRLF line terminators to carriage returns:
% cvt_file.pl --format=csv --ieol="\r\n" --oeol="\r" data.txt > tmp.txt
• Produce a tab-delimited file from the colon-delimited /etc/passwd file:
% cvt_file.pl --idelim=":" /etc/passwd > tmp.txt
• Convert tab-delimited query output from mysql into CSV format:
% mysql -e "SELECT * FROM profile" cookbook \
| cvt_file.pl --oformat=csv > profile.csv
11.7. Extracting and Rearranging Datafile Columns
Problem
You want to pull out only some columns from a datafile or rearrange them into a different
order.
Solution
Use a utility that can produce columns from a file on demand.
Search WWH ::




Custom Search