I have a file like this.
IMS00|20140101|Unix|Jan14
IMS01|20140201|Unix|Feb14
IMS02|20140301|Unix|Mar14
IMS03|20140101|Unix|Jan14
IMS04|20140201|Unix|Feb14
My criteria are, if the column 1 value is IMS00
, then column 4 value Jan14
should be replaced with Jan15
if the column 1 value is IMS01
, then column 4 value Feb14
should be replaced with Feb15
.
How can this be done?
Your question is not very clear, for example in the code you write IMS00
and later on refer to it as IMS.00
, with dot. Also number of changed column should be probably 4
, not 3
. Anyway, you are probably looking for
awk 'BEGIN{FS=OFS="|"}$1=="IMS00"{$4="Jan15"}$1=="IMS01"{$4="Feb15"}1' file
The BEGIN
block executes only once at the very beginning and sets both field separator FS
and output field separator OFS
to |
. Final 1
is just to print everything.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments