You invoke the script like this:
ruby convert_to_csv.rb infile > outfile
So, we take the command line argument infile, open it, and then iterate through each line. In each line, we use the gsub command to substitute a comma for any whitespace (tab, space, newline, etc.). The chop method is used because after running the line through the gsub command, the newline is converted to a comma. We want to change that back to a newline, so, therefore, we chop it off, and then append our newline.
No comments:
Post a Comment