Brace expansion: Difference between revisions

Add ed example
(Add ed example)
 
Line 1,522:
{a,b{2e}f
</pre>
 
=={{header|Ed}}==
 
Only replaces one instance of brace expression. Doesn't replace the nested ones. Doesn't take escaping into account. Still, <tt>ed</tt> was not intended for that but it does work with it, however simplistic that might be.
 
<syntaxhighlight>
H
t
1s/(\{[^}]*\})/%REPLACEME%/
2s/[^{]*\{([^}]*)\}.*/\1/
2s/,/\
/g
2,$g/(.*)/1y\
-1x\
+1s/^/|/\
-1,.j\
s/(.*)%REPLACEME%(.*)\|(.*)/\1\3\2/
1d
,p
Q
</syntaxhighlight>
 
{{out}}
 
<pre>$ cat brace.input
~/{Downloads,Pictures}/*.{jpg,gif,png}
$ cat brace.ed | ed -E brace.input
Newline appended
39
~/Downloads/*.{jpg,gif,png}
~/Pictures/*.{jpg,gif,png}
?
Warning: buffer modified</pre>
 
=={{header|Elixir}}==
{{trans|Ruby}}
66

edits