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

Sorting IP Addresses?

Expand Messages
  • Jason W.
    I ve a list of IP addresses in a text file that I use Notetab to edit (it s a list of IP s my mail server won t accept mail from). I d like to sort by IP
    Message 1 of 7 , May 15, 2005
    • 0 Attachment
      I've a list of IP addresses in a text file that I use Notetab to edit
      (it's a list of IP's my mail server won't accept mail from). I'd like
      to sort by IP address but Notetab just uses the first character. So
      instead of

      64.1.2.3
      127.0.0.1
      233.24.43.5

      Notetab would sort it as

      127.0.0.1
      233.24.43.5
      64.1.2.3

      I understand what it's doing but is there any way to get it to sort as
      a number witout me having to put leading zero's? I'm still learning
      clips syntax and I've no idea how to do it in Clip-ese <g>. I'm not
      even sure I could do ti in Perl... LOL

      --
      TIA :)

      Jason

      EL-M Computer Help List - Computer help for listowners and list moderators
      http://groups-beta.google.com/group/EL-M-ComputerHelp/about

      On June 1, 2001, Steve Ballmer, CEO of Microsoft, told the Chicago
      Sun-Times: "Linux is cancer." Unsurprisingly that's incorrect; LINUX
      was released on August 25th 1991 and is therefore a Virgo.
    • hsavage
      ... Jason, Is there nothing but numbers in your file? I ve engineered a short clip to sort the numerically by making every number a 3 digit number with
      Message 2 of 7 , May 15, 2005
      • 0 Attachment
        Jason W. wrote:

        > I've a list of IP addresses in a text file that I use Notetab to edit
        > (it's a list of IP's my mail server won't accept mail from). I'd like
        > to sort by IP address but Notetab just uses the first character. So
        > instead of
        >
        > 64.1.2.3
        > 127.0.0.1
        > 233.24.43.5
        >
        > Notetab would sort it as
        >
        > 127.0.0.1
        > 233.24.43.5
        > 64.1.2.3

        Jason,

        Is there nothing but numbers in your file? I've engineered a short clip
        to sort the numerically by making every number a 3 digit number with
        leading zeroes.

        It won't work properly unless it's a numbers only file with no
        unnecessary blank lines. Using the examples you sent it seems there are
        only numbers.

        The clip sorts this,

        64.1.2.3
        127.0.0.1
        233.24.43.5
        64.1.2.4
        127.0.0.2
        233.24.43.6

        into this,

        064.001.002.003
        064.001.002.004
        127.000.000.001
        127.000.000.002
        233.024.043.005
        233.024.043.006

        If this is satisfactory and you know how to add a clip into a clipbook
        here is the clip, commented to explain the function.

        ---------
        H="Sort DNS"
        ^!SetScreenUpdate 0
        ; tests last line to ensure it is blank so counters will work
        ^!If ^$GetLineSize(^$GetLineCount$)$ = 0 SKIP_2
        ^!Jump TEXT_END
        ^!InsertText ^%nl%
        ^!Jump 1
        ^!SetListDelimiter .
        :DNS
        ; creates an array from each line, uses period as delimiter
        ^!SetArray %dns%=^$GetLine$
        ^!Set %loop%=0; %count%=^%dns0%
        :LOOP
        ^!Inc %loop%
        ; overwrites data in each field, adds leading zeroes
        ^!InsertText ^$StrCopyRight(00^$GetField(-1;^%loop%)$;3)$
        ; loops to next field in line
        ^!If ^%loop% < ^%count% LOOP
        ; jumps to next line in turn
        ^!Jump +1
        ; tests if cursor has reached last "blank" line
        ^!If ^$GetRow$ = ^$GetLineCount$ SORT
        ^!Goto DNS
        :SORT
        ^!Jump 1
        ; selects to last character of last text(number) line
        ^!SelectTo ^$GetTextLineCount$:15
        ; sorts number sequences in ascending order
        ^!Keyboard SHIFT+Ctrl+X
        ------------

        ºvº
        05.05.15
        hrs > hsavage@...
      • hsavage
        ... Jason, A slightly modified version, hopefully for the best. ... H= Sort DNS ^!SetScreenUpdate 0 ; tests last line to ensure it is blank so counters will
        Message 3 of 7 , May 15, 2005
        • 0 Attachment
          hsavage wrote:

          > Jason W. wrote:
          >
          >> I've a list of IP addresses in a text file that I use Notetab to edit
          >> (it's a list of IP's my mail server won't accept mail from). I'd like
          >> to sort by IP address but Notetab just uses the first character. So
          >> instead of

          Jason,

          A slightly modified version, hopefully for the best.

          -----------
          H="Sort DNS"
          ^!SetScreenUpdate 0
          ; tests last line to ensure it is blank so counters will work
          ^!If ^$GetLineSize(^$GetLineCount$)$ = 0 SKIP_2
          ^!Jump TEXT_END
          ^!InsertText ^%nl%
          ^!Jump 1
          ^!SetListDelimiter .
          :DNS
          ; creates an array from each line, use period as delimiter
          ^!SetArray %dns%=^$GetLine$
          ^!Set %loop%=0; %count%=^%dns0%
          :LOOP
          ^!Inc %loop%
          ; overwrites data in each field, adds leading zeroes
          ^!InsertText ^$StrCopyRight(00^$GetField(-1;^%loop%)$;3)$
          ; loops to next field in line
          ^!If ^%loop% < ^%count% LOOP
          ; jumps to next line in turn
          ^!Jump +1
          ; tests if cursor has reached last "blank" line
          ^!If ^$GetRow$ = ^$GetLineCount$ SORT
          ^!Goto DNS
          :SORT
          ; selects to first character of first text(number) line
          ^!SelectTo 1:1
          ; sorts number sequences in ascending order
          ^!Keyboard SHIFT+Ctrl+X
          ----------

          ºvº
          05.05.15
          hrs > hsavage@...
        • Jason W.
          ... HRS, I tried your clip but it gave me some weird results. I copied your clip starting with the H= line and ending with !^Keyboard line to the cliipbard.
          Message 4 of 7 , May 16, 2005
          • 0 Attachment
            On 5/16/05, hsavage <hsavage@...> wrote:
            > hsavage wrote:

            > Jason,
            >
            > A slightly modified version, hopefully for the best.

            HRS,

            I tried your clip but it gave me some weird results. I copied your
            clip starting with the H= line and ending with !^Keyboard line to the
            cliipbard. After opening my personal clipbook on the left (called My
            Clips), I right-clicked a blank area on the cilpbook and selected Add
            from Clipboard. Sort DNS then showed on my clipbook list. I then
            created a document with IP addresses and a blank line at the end and
            ran your clip by double-clicking Sort DNS in the list. Notetab asked
            what I'd like to name a new clip and it gave me a default value of
            .34000000. Regardless of whether I click OK or Canecel, Notetab zaps
            the document (nothing lost thank goodness :) ). My document isn't
            Read-only on disk or in Notetab and isn't a Pasteboard or anything
            else weird that I know of.

            If I use a document I've saved, I still get the clip creation prompt.
            Here's the clip it creates if I choose OK with the default name.

            H=.34000000
            .34000000
            .81000000
            .27000000
            172000000
            211000000
            .75000000
            .40000000
            .75000000
            238000000
            150000000
            .36000000
            .98000000
            194000000
            .15000000
            111000000
            .98000000
            154000000
            .50000000

            Here's what I get when I chose Edit Clip on Sort DNS with Show Headers
            turned on:

            Sort DNS
            ^!SetScreenUpdate 0
            ; tests last line to ensure it is blank so counters will work
            ^!If ^$GetLineSize(^$GetLineCount$)$ = 0 SKIP_2
            ^!Jump TEXT_END
            ^!InsertText ^%nl%
            ^!Jump 1
            ^!SetListDelimiter .
            :DNS
            ; creates an array from each line, use period as delimiter
            ^!SetArray %dns%=^$GetLine$
            ^!Set %loop%=0; %count%=^%dns0%
            :LOOP
            ^!Inc %loop%
            ; overwrites data in each field, adds leading zeroes
            ^!InsertText ^$StrCopyRight(00^$GetField(-1;^%loop%)$;3)$
            ; loops to next field in line
            ^!If ^%loop% < ^%count% LOOP
            ; jumps to next line in turn
            ^!Jump +1
            ; tests if cursor has reached last "blank" line
            ^!If ^$GetRow$ = ^$GetLineCount$ SORT
            ^!Goto DNS
            :SORT
            ; selects to first character of first text(number) line
            ^!SelectTo 1:1
            ; sorts number sequences in ascending order
            ^!Keyboard SHIFT+Ctrl+X

            Is it something I'm doing wrong? Maybe some option that's not set
            right? I checked in Options and I didn't see anything that'd affect
            clip execution but it does seem like my copy of Notetab isn't behaving
            like yours. I've got Notetab Pro 4.95 on XP Pro. I do have other
            things open that aren't related to my IP stuff - would that cause a
            problem?

            Thanks for the time in writing that clip and hopefully I can get it working.

            --
            Jason

            EL-M Computer Help List - Computer help for listowners and list moderators
            http://groups-beta.google.com/group/EL-M-ComputerHelp/about

            On June 1, 2001, Steve Ballmer, CEO of Microsoft, told the Chicago
            Sun-Times: "Linux is cancer." Unsurprisingly that's incorrect; LINUX
            was released on August 25th 1991 and is therefore a Virgo.
          • hsavage
            ... At this point you should right-click in the clipbook area and select Save, or, Save Now. NoteTab should ask for a name for the clip, I think. I don t use
            Message 5 of 7 , May 16, 2005
            • 0 Attachment
              Jason W. wrote:

              > HRS,
              >
              > I tried your clip but it gave me some weird results. I copied your
              > clip starting with the H= line and ending with !^Keyboard line to the
              > cliipbard. After opening my personal clipbook on the left (called My
              > Clips), I right-clicked a blank area on the clipbook and selected Add
              > from Clipboard. Sort DNS then showed on my clipbook list.

              At this point you should right-click in the clipbook area and select
              Save, or, Save Now. NoteTab should ask for a name for the clip, I think.

              I don't use that system very often, I usually have the clipbook I'm
              working on loaded in the main edit window like any other text document.
              I can see more clearly what's happening that way.

              Then continue with the following

              > I then
              > created a document with IP addresses and a blank line at the end and
              > ran your clip by double-clicking Sort DNS in the list.


              > Is it something I'm doing wrong? Maybe some option that's not set
              > right? I checked in Options and I didn't see anything that'd affect
              > clip execution but it does seem like my copy of Notetab isn't behaving
              > like yours. I've got Notetab Pro 4.95 on XP Pro. I do have other
              > things open that aren't related to my IP stuff - would that cause a
              > problem?

              Jason,

              Aside from the process for adding the clip you didn't do anything wrong,
              the clip is flawed. I had it working time after time last evening, I
              swear. I shut the computer down overnight and when I rebooted this
              morning the clip didn't work.

              I could never get the array parts to work correctly so I modified it
              again and eliminated the array.

              This latest clip and this one works, even after a reboot. Sorry about
              the previous clips.

              -----------
              H="Sort DNS"
              ;_Modified-Updated~Created
              ;_20050516_8:02:40p_hsavage@...
              ^!SetDebug ^$GetValue("Debug:debug")$
              ^!ClearVariables
              ^!SetScreenUpdate 0
              ^!If ^$GetLineSize(^$GetLineCount$)$ = 0 SKIP_2
              ^!Jump TEXT_END
              ^!InsertText ^%nl%
              ^!Jump 1
              ^!SetDelimiter .
              :ROW
              ^!Set %dns%=^$GetLine$
              ^!Set %row%=^$Calc(^$GetRow$-1)$; %col%=0
              ^!Inc %row%
              :COL
              ^!Inc %col%
              ^!Set %row col%=^$GetField(^%row%;^%col%)$
              ^!InsertText ^$StrCopyRight("00^$GetField(^%row%;^%col%)$";3)$
              ^!If ^%col% < 4 COL
              ^!Jump +1
              ^!If ^$GetRow$ = ^$GetLineCount$ SORT
              ^!Goto ROW
              :SORT
              ;^!Jump 1
              ^!SelectTo 1:1
              ^!Keyboard SHIFT+Ctrl+X
              ------------

              The procedure to copy this and add from clipboard is;

              Right-click somewhere in the clipbook window on the left.
              Select 'Add From Clipboard'
              Right-click again, in the clipbook editor, select 'Save Now'.

              Now, proceed to run the clip on a file containing a list of numbers,
              example below.

              9.9.9.9
              8.8.8.8
              7.7.7.7
              64.1.2.4
              64.1.2.3
              6.6.6.6
              5.5.5.5
              4.4.4.4
              3.3.3.3
              233.24.43.6
              233.24.43.5
              2.2.2.2
              127.0.0.2
              127.0.0.1
              1.1.1.1
              0.0.0.0

              ºvº
              05.05.16
              hrs > hsavage@...
            • hsavage
              Jason, Here s one last edition of the clip, it works even after after an overnight reboot. There was 2 superfluous lines that I ve eliminated. They are; ^!Set
              Message 6 of 7 , May 17, 2005
              • 0 Attachment
                Jason,

                Here's one last edition of the clip, it works even after after an
                overnight reboot. There was 2 superfluous lines that I've eliminated.
                They are;
                ^!Set %dns%=^$GetLine$
                - and -
                ^!Set %rowcol%=^$GetField(^%row%;^%col%)$
                these lines are useless line in the clip now.


                H="Sort DNS"
                ;_Modified-Updated~Created
                ;_20050516_8:02:40p_hsavage@...
                ^!ClearVariables
                ^!SetScreenUpdate 0
                ^!If ^$GetLineSize(^$GetLineCount$)$ = 0 SKIP_2
                ^!Jump TEXT_END
                ^!InsertText ^%nl%
                ^!Jump 1
                ^!SetDelimiter .
                :ROW
                ^!Set %row%=^$Calc(^$GetRow$-1)$; %col%=0
                ^!Inc %row%
                :COL
                ^!Inc %col%
                ^!InsertText ^$StrCopyRight(00^$GetField(^%row%;^%col%)$;3)$
                ^!If ^%col% < 4 COL
                ^!Jump +1
                ^!If ^$GetRow$ = ^$GetLineCount$ SORT
                ^!Goto ROW
                :SORT
                ;^!Jump 1
                ^!SelectTo 1:1
                ^!Keyboard SHIFT+Ctrl+X

                --
                ºvº
                05.05.16
                hrs > hsavage@...
              • Jason W.
                ... HRS, Thanks so much for spending time with this. I would have never gotten the correct syntax to loop through the document like that since I m used to
                Message 7 of 7 , May 17, 2005
                • 0 Attachment
                  On 5/17/05, hsavage <hsavage@...> wrote:
                  > Jason,
                  >
                  > Here's one last edition of the clip, it works even after after an
                  > overnight reboot. There was 2 superfluous lines that I've eliminated.

                  HRS,

                  Thanks so much for spending time with this. I would have never gotten
                  the correct syntax to loop through the document like that since I'm
                  used to block-style looping like Perl or C. I did make a few changes
                  tho which I'll document below. BTW, don't worry about the error'ed
                  version - nothing was lost :)

                  > H="Sort DNS"
                  > ;_Modified-Updated~Created
                  > ;_20050516_8:02:40p_hsavage@...

                  [ snip ]

                  > ^!SelectTo 1:1
                  > ^!Keyboard SHIFT+Ctrl+X

                  On my system, the above line was triggering the new Clip dialog. After
                  looking in the menus, it seems my Notetab treats that shortcut as
                  Tools/Clipbook/Cut Selection. I'm wondering if you sort so much that
                  you assigned a hotkey in shortcuts.dat? <grin>

                  I added the following lines (the first one in place of the ^!Keyboard line):

                  ^!Menu Modify/Lines/Sort/Ascending

                  ^!Replace "^0+" >> "" [RSAW]
                  ^!Replace "\.0+" >> "." [RSAW]

                  ^!Jump 1

                  I did the replacing since IP's aren't usually listed with proceeding
                  zero's so it's easier for me if they're gone.

                  Thanks again for doing the heavy clip-writing. It makes it so much
                  easier to detect similar IP's if they're sorted.

                  --
                  Jason

                  EL-M Computer Help List - Computer help for listowners and list moderators
                  http://groups-beta.google.com/group/EL-M-ComputerHelp/about

                  On June 1, 2001, Steve Ballmer, CEO of Microsoft, told the Chicago
                  Sun-Times: "Linux is cancer." Unsurprisingly that's incorrect; LINUX
                  was released on August 25th 1991 and is therefore a Virgo.
                Your message has been successfully submitted and would be delivered to recipients shortly.