How to keep the field separator when printing $0 with awk
@Sukminder has already given the simple answer; I have a couple tidbits of style points and helpful syntax about your example code (like a code review). This started as a comment but it was getting long.
OFS
is the output field separator, as already mentioned.
$0
is the default argument to print
—no need to specify it explicitly. And another style point: awk
has what's called "patterns", which are like built-in conditional blocks. So you could also just use:
awk -F'|' 'BEGIN {OFS = FS} NR != 1 {$5 += 0.1} {print}' myfile
You can set the Output Field Separator, OFS
.
'BEGIN { OFS = "|" } ...'
Or:
'BEGIN { OFS = FS } ...'
It is <space> by default.