Last active
April 26, 2019 09:08
-
-
Save bertrand-lupart/887af550bd38ec4fdd97fb4617f557ff to your computer and use it in GitHub Desktop.
Pike script which trim all whites in CSV data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pike | |
// This script take a dirty CSV as input | |
// Output a white-trimed CSV : spaces, tabs, CR, LF | |
// Set up the following | |
string in_dirty_path = ""; | |
string out_clean_path = ""; | |
int i_ve_set_file_paths = 0; | |
int main(int argc, array(string) argv) | |
{ | |
if(!i_ve_set_file_paths) | |
{ | |
werror("You've not set up file paths\n"); | |
werror("Use the source, Luke\n"); | |
return 42; | |
} | |
object csv_file_in = Public.Standards.CSV.FILE(in_dirty_path); | |
object csv_file_out = Public.Standards.CSV.FILE(out_clean_path,"tcow"); | |
// Looping over lines of the input CSV files | |
foreach(csv_file_in; int csv_line_num; array csv_line_cont_dirty) | |
{ | |
// Building clean data looping over the dirty cells of the current dirty line | |
array csv_line_cont_clean = ({ }); | |
foreach(csv_line_cont_dirty; int index; string dirty_value) | |
{ | |
csv_line_cont_clean += ({ String.trim_all_whites(dirty_value) }); | |
} | |
csv_file_out->write_row(csv_line_cont_clean); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment