Sample file: tab separated
1 2 3 4 |
|
1
|
|
In this case, FS
is the field separator for the input and OFS
is the field separator for the output. Thus if we wanted to go to eg tsv to tsv we would set both to "\t"
(default for awk
); csv to csv would be FS=', '
and OFS = ', '
, etc. Of course, you can also replicate columns by repeating them, eg $1,$1,$3,$2,$3
would output 5 columns of which 2 are replicated. In fact, there are all sorts of neat tricks that one can play with awk
.
Again, this is far easier in R, but sometimes either the overhead of loading data into R is too much (R will happily work with millions of rows, but I regularly end up working with tens or hundreds), or R isn’t available, or you really want to automate a process (that also can be done inside R, but still). Equivalent code in R would go something like:
1 2 3 4 5 6 |
|
And of course, if you needed to replicate the columns in R, you could say
1 2 |
|