Loading ...
Sorry, an error occurred while loading the content.

Re: delete only the short sentences

Expand Messages
  • Tim Chase
    ... And to reverse the condition, one could use something like ... ( if there s a character at position 40, don t delete this row; otherwise, delete it ) -tim
    Message 1 of 11 , Nov 1, 2010
    • 0 Attachment
      On 10/31/10 23:14, Joan Miquel Torres Rigo wrote:
      > 2010/11/1 AMDx64BT<amdx64bt@...>:
      >> And to keep only the sentences in the range 40-60 characters long and
      >> delete the rest?
      >
      > :g/^.\{,39\}$/d
      >
      > and
      >
      > :g/\(^.\{,39\}$\)\|\(^.\{61,\}$\)/d

      And to reverse the condition, one could use something like

      :v/\%40c./d

      ("if there's a character at position 40, don't delete this row;
      otherwise, delete it")

      -tim



      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tim Chase
      ... Actually, the problem is the reverse -- it fails to delete lines ... so any line that doesn t have a character at position 40 (lines
      Message 2 of 11 , Nov 1, 2010
      • 0 Attachment
        On 11/01/10 07:40, Joan Miquel Torres Rigo wrote:
        > 2010/11/1 Tim Chase<vim@...>:
        >> :v/\%40c./d
        >>
        >> ("if there's a character at position 40, don't delete this
        >> row; otherwise, delete it")
        >
        > Then you will also remove rows with 61 to 80 characters.
        >
        > But the strategy is probably good. (I'm not fully expert with
        > vim's regular expressions yet and I don't know the meaning of
        > '%' in this context).

        Actually, the problem is the reverse -- it fails to delete lines
        > 80 characters. The \%40c is an atom that matches at column 40

        :help /\%c

        so any line that doesn't have a character at position 40 (lines
        <40 chars) will be deleted. (note that I don't anchor the
        column-position to the end-of-line) I'd usually[1] do this as a
        2-pass, taking out those >80 in the 2nd pass:

        :v/\%40c./d " delete anything shorter than 40
        :g/\%81c./d " delete anything longer than 80

        I might have some fence-posting errors in there, so 40 might need
        to be 39 or 41 and 81 might also be +/- 1, but the logic still holds.

        -tim


        [1]
        Yes, I've had to do the same thing as the OP on several occasions
        with various shorter/longer-than thresholds; usually in
        column-delimited files with garbage before/after the actual data.

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • ZyX
        Reply to message «Re: delete only the short sentences», sent 17:21:40 01 November 2010, Monday ... s/character/byte/ %c does nothing with characters, it
        Message 3 of 11 , Nov 1, 2010
        • 0 Attachment
          Reply to message «Re: delete only the short sentences»,
          sent 17:21:40 01 November 2010, Monday
          by Tim Chase:

          > On 11/01/10 07:40, Joan Miquel Torres Rigo wrote:
          > > 2010/11/1 Tim Chase<vim@...>:
          > >> :v/\%40c./d
          > >>
          > >> ("if there's a character at position 40, don't delete this
          > >> row; otherwise, delete it")
          > >
          > > Then you will also remove rows with 61 to 80 characters.
          > >
          > > But the strategy is probably good. (I'm not fully expert with
          > > vim's regular expressions yet and I don't know the meaning of
          > > '%' in this context).
          >
          > Actually, the problem is the reverse -- it fails to delete lines
          >
          > > 80 characters. The \%40c is an atom that matches at column 40
          > >
          > :help /\%c
          >
          > so any line that doesn't have a character at position 40 (lines
          > <40 chars) will be deleted. (note that I don't anchor the
          > column-position to the end-of-line) I'd usually[1] do this as a
          >
          > 2-pass, taking out those >80 in the 2nd pass:
          > :v/\%40c./d " delete anything shorter than 40
          > :g/\%81c./d " delete anything longer than 80
          >
          > I might have some fence-posting errors in there, so 40 might need
          > to be 39 or 41 and 81 might also be +/- 1, but the logic still holds.
          >
          > -tim
          >
          >
          > [1]
          > Yes, I've had to do the same thing as the OP on several occasions
          > with various shorter/longer-than thresholds; usually in
          > column-delimited files with garbage before/after the actual data.

          s/character/byte/
          \%c does nothing with characters, it operates on byte columns. You should use
          \%v for displayed columns (unless you have a tab or non-printable character
          somewhere before Nth character, \%Nv will match at Nth character).
        • AMDx64BT
          Thanks for the solution. It works. I would like to know how I can delete sentences
          Message 4 of 11 , Nov 7, 2010
          • 0 Attachment
            Thanks for the solution. It works. I would like to know how I can
            delete sentences < 40 characters only when they are more than 3 times
            consecutives.

            For example, with this text:

            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx

            Obtain this:

            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            Thanks in advance.

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Christian Brabandt
            Hi AMDx64BT! ... regards, Christian -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
            Message 5 of 11 , Nov 7, 2010
            • 0 Attachment
              Hi AMDx64BT!

              On So, 07 Nov 2010, AMDx64BT wrote:

              > Thanks for the solution. It works. I would like to know how I can
              > delete sentences < 40 characters only when they are more than 3 times
              > consecutives.
              >
              > For example, with this text:
              >
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
              > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              >
              > Obtain this:
              >
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxx
              > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
              > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
              >
              > Thanks in advance.

              try this:
              :s/\_^\(.\{,40}\n\)\{4,}//

              regards,
              Christian

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • rameo
              ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit
              Message 6 of 11 , Nov 7, 2010
              • 0 Attachment
                or this one:

                :v/^.\{41,}/d

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • AMDx64BT
                ... another question. Could be possible to delete all the sentences
                Message 7 of 11 , Nov 8, 2010
                • 0 Attachment
                  :%s/\_^\(.\{,40}\n\)\{4,}// works very well. I would like to do
                  another question.
                  Could be possible to delete all the sentences < 40 characters only
                  when they are more than 3 times consecutives "but now keeping the last
                  one undeleted of each group". I want to say this:

                  Begining with this:

                  xxxxxxxxxx
                  xxxxxxxxxx
                  xxxxxxxxxx
                  xxxxxxxxxx
                  xx--Title--xx
                  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                  And obtain this:

                  xx--Title--xx
                  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Christian Brabandt
                  Hi AMDx64BT! ... regards, Christian -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
                  Message 8 of 11 , Nov 8, 2010
                  • 0 Attachment
                    Hi AMDx64BT!

                    On Mo, 08 Nov 2010, AMDx64BT wrote:

                    > :%s/\_^\(.\{,40}\n\)\{4,}// works very well. I would like to do
                    > another question.
                    > Could be possible to delete all the sentences < 40 characters only
                    > when they are more than 3 times consecutives "but now keeping the last
                    > one undeleted of each group". I want to say this:
                    >
                    > Begining with this:
                    >
                    > xxxxxxxxxx
                    > xxxxxxxxxx
                    > xxxxxxxxxx
                    > xxxxxxxxxx
                    > xx--Title--xx
                    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                    >
                    > And obtain this:
                    >
                    > xx--Title--xx
                    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                    > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                    :%s/\_^\%(.\{,40}\n\)\{3,}\(.\{,40}$\)/\1/

                    regards,
                    Christian

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  Your message has been successfully submitted and would be delivered to recipients shortly.