Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Easier way to toggle comments?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Todd A. Jacobs  
View profile  
 More options Apr 2 2011, 7:38 pm
From: "Todd A. Jacobs" <nos...@codegnome.org>
Date: Sat, 2 Apr 2011 16:38:31 -0700 (PDT)
Local: Sat, Apr 2 2011 7:38 pm
Subject: Easier way to toggle comments?
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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mëa Cúlpa  
View profile  
 More options Oct 17 2011, 12:23 am
From: Mëa Cúlpa <infern...@gmail.com>
Date: Mon, 17 Oct 2011 04:23:58 +0000 (UTC)
Local: Mon, Oct 17 2011 12:23 am
Subject: Re: Easier way to toggle comments?
Todd A. Jacobs <nos...@codegnome.org>:

Why not use printf instead of sub?

awk ' /^[^#]/ {printf("#%s\n", $0)}'

Regarding elegance,

A full-featured awk script is elegant enough.
What else do you want if you have a line-based, regex-powered,
C-flavoured Just-In-Time interpreter like AWK??

--
- Mëa Cúlpa  - infernoxu at gmail dot com
- http://ucarenya.com/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephane CHAZELAS  
View profile  
 More options Oct 17 2011, 4:49 am
From: Stephane CHAZELAS <stephane_chaze...@yahoo.fr>
Date: Mon, 17 Oct 2011 08:49:45 +0000 (UTC)
Local: Mon, Oct 17 2011 4:49 am
Subject: Re: Easier way to toggle comments?
2011-10-17, 04:23(+00), Mëa Cúlpa:

[...]

sed -e 's/^#//;t' -e 's/^/#/'

Or

awk '{print /^#/ ? substr($0,2) : "#" $0}'

--
Stephane


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »