String length: Difference between revisions

→‎sed: de-obfuscate & simplify
m (→‎{{header|Kotlin}}: made the kotlin example not use java)
(→‎sed: de-obfuscate & simplify)
Line 3,029:
Text is read from standard input e.g. <code>echo "string" | sed -f script.sed</code> or <code>sed -f script.sed file.txt</code> (The solution given would be the contents of a text file <code>script.sed</code> in these cases).
For files with more than one line, sed will give a count for each line.
<syntaxhighlight lang="sed"># Changecreate allunary charactersnumeral to(i '|'.= 1)
The 'convert to digits' section is based off of [http://unix.stackexchange.com/a/36959/11750 this StackExchange answer].
s/./\|i/g;
<syntaxhighlight lang="sed"># Change all characters to '|'.
:loop
s/./\|/g;
# divide by 10 (x = 10)
 
s/i\{10\}/x/g
# Convert to digits
# convert remainder to decimal digit
:convert
/i/!s/[0-9]*$/0&/
s/||||||||||/</g
s/<i\([0-{9]*\)$}/<0\19/g
s/|||||||||i\{8\}/98/g;
s/i\{7\}/7/
s/|||||||||/9/g; s/||||||||/8/g; s/|||||||/7/g; s/||||||/6/g;
s/i\{6\}/6/
s/|||||/5/g; s/||||/4/g; s/|||/3/g; s/||/2/g; s/|/1/g;
s/<iiiii/|5/g
s/iiii/4/
t convert
s/iii/3/
s/^$/0/</syntaxhighlight>
s/ii/2/
s/i/1/
# convert quotient (10s) to 1s
y/x/i/
# start over for the next magnitude (if any)
s/^$/0i/b loop</syntaxhighlight>
 
=={{header|Seed7}}==
559

edits