Longest common prefix: Difference between revisions

m
sed: simplify for improved compatibility
(add sed)
m (sed: simplify for improved compatibility)
Line 3,374:
 
=={{header|sed}}==
<syntaxhighlight lang="sed">1!{$q
N
G
s/^\([^\n].*\)[^\n].*\(\n\)\1.*/\2\1/
$!dD</syntaxhighlight>
}
h
$!d</syntaxhighlight>
{{out}}
<pre>
Line 3,390 ⟶ 3,388:
$ printf '%s\n' throne '' throne | sed -f lcp.sed
 
$ printf '%s\n' cheese | sed -f lcp.sed
cheese
$ printf '%s\n' '' | sed -f lcp.sed
559

edits