<!-- language: shell -->
sed ':n
s|;N/A;|;|g;$!N
s|^\(\([^;]*;\)\{3\}\)\(.*\)\n\1|\1\3;|;tn
P;D
' <<\IN
D04005;4;279;0;0;SSM-4-1
D04005;5;40;0;0;SSM-5-1
LE040A;1;363;(26.3);N/A;SM-1-1
LE040A;1;363;(27.4);N/A;SM-1-2
LE040A;1;363;(28.5);N/A;SM-1-3
LE040A;1;363;(29.6);N/A;SM-1-4
IN
That will continue to branch back to `t`est for every sequential in input, merging only the tails for each.
That's portably written, but it is a little easier to write if you can use *`-E`* xtended regular expressions *(as you might w/ BSD or GNU versions)*...
<!-- language: shell -->
sed -E ':n
s|;N/A;|;|g;$!N
s|^(([^;]*;){3})(.*)\n\1|\1\3;|;tn
P;D'
If you wanted it all on one line:
<!-- language: shell -->
sed -Ee:n -e's|;N/A;|;|g;$!N;s|^(([^;]*;){3})(.*)\n\1|\1\3;|;tn' -eP\;D
...would work, but I've never been very fond of *one-liners* like that...
Anyway, the output from the first there, is:
###OUTPUT
D04005;4;279;0;0;SSM-4-1
D04005;5;40;0;0;SSM-5-1
LE040A;1;363;(26.3);SM-1-1;(27.4);SM-1-2;(28.5);SM-1-3;(29.6);SM-1-4