Editor’s Note :
This question has a problematic history of changes in that well-designed but erroneous editing (which introduced unrelated, “pretty” formatting based on spaces and characters |to separate columns) temporarily confused the problem (since it returned) .
The premise of the OP is that the input is separated by tabs, even if it is not directly reflected in the sample presented here.
I have an input file having 6 columns and they are separated by tabs. I want to replace all the values in column 5 with a value '81115'while keeping the formatting intact.
Input file:
203 ADD 24 IAC 81216 IT
204 ATT 24 IAC 81216 IT
Desired output file:
203 ADD 24 IAC 81115 IT
204 ATT 24 IAC 81115 IT
My solution # 1
:
awk '{$5 = v} 1' v="81115" file > file.NEW
5 , .
:
203 ADD 24 IAC 81115 IT
204 ATT 24 IAC 81115 IT
# 2
, :
awk -v replace="81115" -F '\t' -v OFS='\t' {$5=replace}1' file > file.NEW
awk -F"\t" -v OFS="\t" '{$5=81115}1' file > file.NEW
awk -F '\t' '{$5="81115";}1' OFS='\t' file > file.NEW
, 81115; .. 7.
:
203 ADD 24 IAC 81216 IT 81115
204 ATT 24 IAC 81216 IT 81115
- ?