Trimming Lines in a CSV File Using awk
In many instances, you might want to trim or extract only a specific number of characters from every line in a file. The awk
command provides a flexible way to achieve this.
Command Overview
awk '{ print substr($0, 1, 14) }' rs.csv > rs_modified.csv
Breakdown
-
'{ print substr($0, 1, 14) }'
:print
: This tellsawk
to output something.substr($0, 1, 14)
: This function extracts a substring from the entire line ($0
). It starts at the first character and captures up to the 14th character.
-
> filename_modified.csv
: This redirects the output of theawk
command into a file namedfilename_modified.csv
.