I recently had a question that was answered but I was writing in shell with cygwin
. I found out I need to make this krn
Shell compatible for MKS
Toolkit.
The sed
command does not like this and I am looking for a solution. the file is such that anything ending with -0
needs a date change with user input.
137611B 0000000130220419 000013012632286-0003-0
137618C 0000000120220420 000012012635623-0003-0
141414-001B 0000000600220421 000060012629222-0003-1
141608A 0000000010220422 000001012634368-0003-1
146223C 0000000030220420 000003012626555-0003-1
146327A 0000000020220422 000002012633825-0003-1
137149D 0000000045220419 000004512632587-0003-0
137050C 0000000018220419 000001812632410-0003-0
137147A 0000000045220419 000004512632487-0003-0
137233B 0000000144220421 000014412630711-0003-1
[[ $user_date = $(date -d "$user_date" +'+%y%m%d') ]]
for i in "$user_date"
do
sed -E '/-0$/{s/ ([^ ]{1,10})[^ ]* / \1'"$user_date"' /2}' ../*.txt > ../neworder.txt
done
suggesting single line awk
:
awk '/-0\s*$/{$2=gensub("[0-9]{6}$",d,1,$2)}{printf("%-12s%s %s\n",$1,$2,$3)}' d="$(date '+%y%m%d')" *.txt