I have a problem in which Input file has Effective date and End date records. First 6 fields are the keys (12345A). We need to update End date(18 position) based on effective(8 position) date of the next record with same key - 1 day. For the records with newest effective date, 9999-12-31 should remain in End date. Below are the input and output expectations. Could someone please help me in this. I am fetching the file A as table unload and this has to be send later to interfacing application which is expected the end date to be populated like this, we can not change end date on table itself thats why we are trying to change it on unload file.
There is no data separator/delimiter and yes length of keys will always remain same.
Input (FILEA):
12345A22021-01-259999-12-31 12345A12021-01-019999-12-31 12345B32021-02-159999-12-31 67899C12021-03-019999-12-31 67899D32021-05-249999-12-31 67899D22021-04-029999-12-31
Output (FILEB):
12345A22021-01-259999-12-31 12345A12021-01-012021-01-24 12345B32021-02-159999-12-31 67899C12021-03-019999-12-31 67899D32021-05-249999-12-31 67899D22021-04-022021-05-23
2021-01-24
in line 2, while line 1 has2021-01-25
as effective date? Same for line 6 (05-23
instead of05-24
)? Otherwise something likesed -E 'N;s/^(.{6})(.)(.{10})(.*\n\1.{11}).*/\1\2\3\4\3/;P;D' fileA > fileB
would do the trick.sed
version is quite old and does not support extended regular expressions. You can use standard regular expressions by adding a couple of backslashes:sed 'N;s/^\(.\{6\}\)\(.\)\(.\{10\}\)\(.*\n\1.\{11\}\).*/\1\2\3\4\3/;P;D' fileA > fileB
, but you still need to decrement the date …