Swap CSV columns
Swap CSV columns
Description
Swap CSV columns by exchanging two header fields.
Input files
- at least 1 input file (.csv)
Output files
This is a converter script which produces a swapped results file for every input input file.
Context
Example
Using the following table as input:
Item | Cost |
---|---|
Apple | 0.25 |
Banana | 0.25 |
Orange | 0.40 |
Fruit hip holster | 10.00 |
...the following table results if 'Item' and 'Cost' are specified as column names:
Cost | Item |
---|---|
Apple | 0.25 |
Banana | 0.25 |
Orange | 0.40 |
Fruit hip holster | 10.00 |
Please note that only the header line is modified.
Common CSV file problems
CSV files must be plain text files, using , as the entry separator, and " as the optional quote character. The quote character is used to denote a cell if the entry separator is part of the cell content. The first line is expected to represent the table header, all following lines are expected to represent table rows.
Parameters
- Column A
-
Examples: Amount light, Amount heavy, peptide, protein, defline, scan count, PBC count, Ratio mean, Ratio SD, Ratio RSD, charge, filename
- Column B
-
Examples: Amount light, Amount heavy, peptide, protein, defline, scan count, PBC count, Ratio mean, Ratio SD, Ratio RSD, charge, filename
Source code
swap-csv-columns.rb, swap-csv-columns.yaml (GitHub)