Quote:
Originally Posted by vladtz
Yup, you are pedantic... but, aren't we all?
Just put everything between the single quotes in a file (palindromes.sed) and run sed -f palindromes.sed file...
It will then be 100% pure sed :-)
The shell in the example doesn't add anything at all (just turns the whole thing in a convenient filter form).
|
OK, I'll go further than hint.
The form I called pedantic requires 2 processes. Filters should by nature, since you don't know how they will be called, be as cheap as possible, and no impose unnecessary performance penalties. There is too easy a solution around that penalty in this case.
Filters should not require a user to specify arbitrary script files to include.
Filters should not require a user to type out the filter script on the command line.
So, the best solution, requires 1 process invocation, no specifying of a script file, or typing of a script. Use the kernels built in interpreter execution syntax instead, placing the contents below into a file that is then made executable:
Code:
#!/usr/pkg/bin/gsed -nf
h
s/^/\n/
:again
s/\(.*\n\)\(.\)/\2\1/
t again
G
/^\(.*\)\n\n\1$/{
x
p
}