3 ms·
'tr' and 'cut' are also very useful; 'tr' can be used to get rid of extra spaces and to conver commas to spaces and vice versa (and to handle text data with pre
by zh3 3y ago
'tr' and 'cut' are also very useful; 'tr' can be used to get rid of extra spaces and to conver commas to spaces and vice versa (and to handle text data with pretty much any character used as a separator).
'cat $SPACE_SEPARATED_FILE | tr -s ' ' | tr ' ' ',' > out.csv
Allied with 'cut', it becomes easy to pull particular fields out of a text file:-
'cat $FILE_WITH_COMMAS_AND_SPACES | tr ',' ' ' | tr -s ' ' | cut -d ' ' -f1,2,17 > out.txt