> Todd A. Jacobs <
nos...@codegnome.org>:
>> I'm using the following to toggle lines on and off in my Ruby .gemrc
>> file:
>>
>> toggle-rdoc () {
>> local FILE="$HOME/.gemrc"
>> { rm $FILE &&
>> awk '/^#/ {sub(/^#/, "", $0); print; next};
>> /^[^#]/ {sub(/^/, "#", $0); print}' > $FILE
>> } < $FILE
>> cat $FILE
>> }
>>
>> It works, but it just seems like there ought to be an easier way. I
>> couldn't get it to work with sed for some reason; it seems to need
>> some serious branching to work at all in sed. Here's what I tried in
>> sed:
>>
>> alias toggle-rdoc='sed -ri "/^#/{ s/^#// }; s/^([^#])/#\1/"
>> ~/.gemrc; cat ~/.gemrc'
>>
>> but the results are always the same; no toggling happens at all.
>> *sigh*
>>
>> Can anyone think of a more elegant solution for this problem?
>>
>
> Why not use printf instead of sub?
>
> awk ' /^[^#]/ {printf("#%s\n", $0)}'