I have the following command with which I can change the field separator for an entire record
$ echo "DOWN_COMP_002_wget_001_6_2020-04-10-13_40_27_395533885" | awk 'BEGIN{FS="_|-";OFS="::"} {$i=$i } 1'
DOWN::COMP::002::wget::001::6::2020::04::10::13::40::27::395533885
But i only want the last seven columns i.e 2020::04::10::13::40::27::395533885
I can try to do that with
$ echo "DOWN_COMP_002_wget_001_6_2020-04-10-13_40_27_395533885" | awk 'BEGIN{FS="_"} {for(i=7;i<=NF;i++) printf $i"::"}'
6::2020-04-10-13::40::27::395533885::
But this will add an ::
at the end which I don't want.
So how can I do this using OFS for the last N columns?
CONCLUSION FROM ANSWERS:
I was looking if there is any possible way with OFS
The solutions i saw below are not using the OFS. So its not possible using OFS
So the alternate solution is either to use sed
or if
inside awk
which i am already aware of
So OFS is useful only when we manually do it like below
print $1,$3,$5
Then the question is:
So is there a away to generate print print $1,$3,$5....
programitcally so that OFS is automatically used.
-
in the date replaced by::
, or you won't. Which is it? Also,2020::04::10::13::40::27::395533885
looks like seven columns, not six, and6::2020-04-10-13::40::27::395533885
is five.