Quote:
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 |
OK, yes I did consider doing it that way (did forget about the -n though).
I agree completely. |
In case anyone else uses the posted sed script - I believe one correction is needed ---
instead of sed '1,/^$/ {/^$/a\ aaaa }' it should be sed '0,/^$/ {/^$/a\ aaaa }' The difference is apparent only for an input in which both the first two lines are blank. The originally posted script will add the aaaa line twice. The corrected one will do so only for the first blank line as specified. John |
sed might not be able to recognize palindromes
I am not totally certain about this, but I believe that sed cannot recognize arbitrarily long palindromes. Sed has the power of regular expressions, which is equivalent to deterministic finite automaton (DFA) which is also provably equivalent to a non-deterministic finite automaton (NDFA, also known as NFA). But this is not sufficient to recognize arbitrarily long palindromes. Recognizing arbitrarily long palindromes requires the power of a push-down automaton (PDA). The NFA is not equivalent to the capability of a PDA.
|
Just in case another awk alternative might be considered:
Code:
awk '/^$/ && !f++ && gsub(//,"&\nnext")||1' file |
This thread is over 2 years old!
|
oops ... sorry ... didn't look at date of original :( my bad :redface:
|
Variables
Quote:
|
Yes - simply use double-quotes instead of single and then explicitly quote the $ and \ chars :
e.g. addw=foobar;echo -e "\\n\\n" | sed "0,/^\$/ {/^\$/ a \\ ${addw} }" |
All times are GMT -5. The time now is 02:19 AM. |