I had this question before and used @HatLess answer when it was going to be static. It needs to be user input and I have tried the script but I am having issues as it tells me file not found and several other messages depending on what I change. I am doing this in a korn shell.
This is an example of my text file
126731E 0000000033220422 000003312634460-0003-1
134180D 0000000052220419 000006012622399-0003-1
134307-004K 0000000016220420 000001612635621-0003-0
141014-001B 0000000040220419 000004012632585-0003-0
134886C 0000000034220419 000007612620821-0003-1
123899B 0000000050220412 000005012635007-0003-1
121543C 0000000059220419 000007512621925-0003-1
118238C 0000000070220419 000007012632584-0003-0
121852A 0000000122220419 000013512622569-0003-1
123124A 0000000141220419 000014112631954-0003-0
123157C 0000000344220422 000034412634707-0003-1
This is an image of where the date needs to change (highlighted)
This is the end result
126731E 0000000033220422 000003312634460-0003-1
134180D 0000000052220102 000006012622399-0003-1
134307-004K 0000000016220420 000001612635621-0003-0
141014-001B 0000000040220419 000004012632585-0003-0
134886C 0000000034220102 000007612620821-0003-1
123899B 0000000050220412 000005012635007-0003-1
121543C 0000000059220102 000007512621925-0003-1
118238C 0000000070220419 000007012632584-0003-0
121852A 0000000122220102 000013512622569-0003-1
123124A 0000000141220419 000014112631954-0003-0
123157C 0000000344220422 000034412634707-0003-1
220102 would be from a user input and I have that covered but I cannot get it to be used in the sed command. I have tried the sed in the script and calling a separate script. I possibly modified this sed trying to make it work but it still isn't any help.
export GLOBAL_UTILS="../../utils"
broken_date=`$GLOBAL_UTILS/accept_date.ksh "$title" "$message" "$btn_width" "$btn_1_txt" "$btn_2_txt"`
print $broken_date
sed -f [^ ]\+0\+\([1-9]\)\([0-9]\{1,3\}\)\([0-9]\{6\}\)0\+\1\?\2/!{s/[0-9]\{6\}/"$broken_date"/ ../1111003.txt > new.txt
accept_date.ksh is just a script that opens a user input box and it works perfect. I get the date entered into the variable I just cannot pass what I entered into the sed command. Thanks in advance
Here is the original sed command
/[^ ]* \+0\+\([1-9]\)\([0-9]\{1,3\}\)\([0-9]\{6\}\).* 0\+\1\?\2/!{
s/[0-9]\{6\} /220102 /
}
this is the sed unknown I get which looks like it added the 220909 that I unput but then tells me there is unknown command.
+ + echo 220909
RESULT=220909
+ break
+ + echo 220909
+ bc
date_in=220909
+ [ 220909 -lt 200101 ]
+ [ 220909 -gt 501231 ]
+ dlg close
+ break
+ echo 220909
broken_date=220909
print $broken_date
+ print 220909
220909
sed -Ee "/[^ ]* +0+([1-9])([0-9]{1,3})([0-9]{6}).* 0+\1?\2/ ! {s/[0-9]{6} /$broken_date /" -e '}' ../1111003.txt > .
./new.txt
+ sed -Ee /[^ ]* +0+([1-9])([0-9]{1,3})([0-9]{6}).* 0+\1?\2/ ! {s/[0-9]{6} /220909 / -e } ../1111003.txt
sed: unknown command