Did you ignore my answer? It does exactly what you asked now the 2nd time. I just forgot to add the word "return" in the first line but it doesn't matter generally and can be added. Result should be the same.
sorry Zaxxon....I am not much familiar with shell scripting. Just learning now. I dont know exact use of "sed" command. I just copied ur code and tried here .
But error coming "sed: command garbled: /&$/ {N; s/&\n//}; ta"
At first:
Please use CODE-tags when you display code, data or logs. It really enchances readability, formatting and preserves special characters. It could happen that you might get a warning or a charge on bits of your forum account if you proceed like that
Hm...
:a is a label and as long as the condition is true ie. the last character in the line is a & it should start over at the label :a. :ta just says "if-true-go-to-a.
I am not sure but I have something similar on AIX where I have only a plain sed. It seems it is expecting the commands inside the curled bracket one per line. Here the problem I get like you got:
> sed -e :a -e '/&$/ {N; s/&\n//}; ta' infile
sed: 0602-404 Function /&$/ {N; s/&\n//}; ta cannot be parsed.
Here changed so it is working:
$> sed -e :a -e '/&$/ {
> N
> s/&\n//
> }
> ta' infile
abcdefghijklmnopqrstuvwxyz
some
more bla
undef $/;
$str=<DATA>;
my @arr=split(/(?:[^&])\n/,$str);
map {s/&[^:]*:\s*//g} @arr;
print join "\n", @arr;
__DATA__
line 1 : return abcdefgh&
line 2 : ijklmnopqr&
line 3 : stuvw&
line 4 : xyz
line 1 : return abcdefgh&
line 2 : ijklmnopqr&
line 3 : stuvw&
line 4 : xyz
line 1 : return abcdefgh&
line 2 : ijklmnopqr&
line 3 : stuvw&
line 4 : xyz