I have a file that contains many lines (line separator ~). In each line, I have many elements separated by the separator '*'. I want to do this, I will have a line that starts with the line TRN in my file. It may contain 4 (including TRN) or more data points. Sort of,
TRN*1*S521000035*1020494919~ TRN*1*S521000035*1020494919*787989800~
I want to replace the fourth data point from these rows with abc123. i.e,
TRN*1*S521000035*abc123~ TRN*1*S521000035*abc123*787989800~
I tried using sed command with regex
sed -i 's/^TRN\*(.*)\*(.*)\*(.*)$/abc123/g' file.txt
But the whole line is replaced with abc123.
Is it possible to change only the 4th data channel with the sed command?
source share