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

Re: Redirecting GAWK Output

Expand Messages
  • mycroftj
    I am going to be teaching myself GAWK as soon as I have some time and this is a question I m sure I will want the answer to. I know very little so far but have
    Message 1 of 16 , May 12, 2012
      I am going to be teaching myself GAWK as soon as I have some time and this is a question I'm sure I will want the answer to.

      I know very little so far but have some quick ideas that might lead you somewhere.

      The first was selecting ALL and saving it. Then run the GAWK code and scoop up the results like you did then paste it all back. Not much better than what you did.

      Um, is it possible to add a line to your GAWK subroutine like PRINT $0 so all the lines are put back automatically? Then retrieve your answer from the end of the document and remove it.

      Then I was thinking of using ^$GetDosOutput$ or one of those similar commands. Honestly, I'm not clear on what ^$GetInputOutput$ or ^$GetOutput$ do. I wish there were some examples in the help. Perhaps creating a subroutine to output the desired text (input data) to a saved file and running GAWK in DOS passing the file to it. I suppose the code would have to be saved in a file and passed also. But then the output may be obtained using ^$GetDosOutput$. It would be easier after the subroutines that do most of the work are created.

      I do want to start messing with this and will let you know if I figure something better out. Please do the same!

      Thank you

      Joy


      --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
      >
      > Hi GAWK experts!
      >
      > I can clearly see how to run a GAWK script from a NT clip. But I get into trouble whith redirecting GAWK output to a clip. Example:
      >
      > Given some lines...
      >
      > Adelaide
      > Adria
      > Karkonjafarabadi
      > Karolyne
      > Rob
      >
      > I try to find out the size of the longest name. The GAWK script...
      >
      > # Find size of longest line
      > { if (length($0) > max) max = length($0) }
      > END { print max }
      >
      > will perfectly output '16' as the size of the third name but it replaces the whole list with '16'.
      >
      > So far, my work-around for that has been this...
      >
      > ; Copy whole list to a new document
      > ^!Toolbar Copy All
      > ^!Toolbar Paste New
      > ; Run GAWK script "Longest" (subclip in same library)
      > ^!RunGawk Longest
      > ; Copy result to clipboard
      > ^!SetClipboard ^$GetText$
      > ; Close second document
      > ^!Close Discard
      > ; Display result in infobox
      > ^!Info The longest name has ^$GetClipboard$ characters
      >
      > Could anyone explain to me please if there's a shorter way to redirect the GAWK result to the clip without overwriting the list?
      >
      > In my naive view, there should be a solution that redirects the GAWK result directly to the clipboard or a variable so the clip could call the result from there.
      >
      > Thanks for advice!
      >
      > Flo
      >
    • flo.gehrke
      ... Kees, Thanks, your solution is (almost) perfectly doing the job! Also thanks to Joy for considering this problem. The only drawback is that we still have
      Message 2 of 16 , May 13, 2012
        --- In ntb-scripts@yahoogroups.com, Kees Nuyt <k.nuyt@...> wrote:
        >
        > The canonical way to keep the list intact is to always include
        > a print action:
        >
        > ==========================================
        > BEGIN{
        > # init code
        > max = 0
        > outfile = "/path/to/your/output/filename.txt"
        > }
        > # echo input to original file
        > {
        > print
        > }
        > # the rest of the script
        > (length($0) > max){
        > max = length($0)
        > }
        > END{
        >
        > # choose one of these output options:
        > print max >outfile # overwrite outfile
        > print max >>outfile # append to outfile
        > close(outfile)
        > }
        > ==========================================
        >
        > As the next step, the clip can pickup the output file.
        >
        > Hope this helps.
        >
        > Regards,
        >
        > Kees Nuyt


        Kees,

        Thanks, your solution is (almost) perfectly doing the job! Also thanks to Joy for considering this problem.

        The only drawback is that we still have to create an output file. Is there no way to redirect the output from GAWK to the clipboard, for example, without saving it to the disk?

        Furthermore, it obviously is overwriting the list with the source text. Is there no way to avoid this and to leave the list completely untouched? (Without those work-arounds I described.)

        There was a similar topic in the Clip Group (Robert Bull, Using scripts in clips?, 16.10.2011, message #22161). In that discussion, diodeom described how he is combining a clip with Lua. Since it's based on '^$GetOutput$' it's similar to the idea that Joy had in mind:

        ;[path to exe]
        ^!Set %lua%=
        ;[path to the script]
        ^!Set %script%=
        ;[text to process, e.g. ^$GetSelection$, ^$GetClipboard$]
        ^!Set %input%=
        ^!InsertText ^$GetOutput(^%lua% "^%script%" "^%input%")$

        I tried to reproduce this with GAWK but I can't get it to work. For me, GAWK doesn't seem to accept the input from that ^%input% variable.

        It works when getting the input from a file:

        ^!Info ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^$GetDocumentPath$input.txt)$

        This is a solution that spares us the output file but it's no solution for getting the input just from the active document (via clipboard, ^$GetText$, ^%input% etc) and not from a file. Also, it can't call the script from inside the same clipbook but from a script file only.

        So, in my view, we could do with some more ideas for...

        - getting the input from an active document and not from a file

        - leaving that document completely unchanged

        - redirecting the output directly to NT, maybe via the clipboard, and not to an output file in order to immediately process that output with further clip commands. We've seen, of course, how to redirect it to a file, and we could easily use ^$GetFileText%, for example, to achieve this. But I still wonder if we could avoid that detour.

        Regards,
        Flo
      • Robert Bull
        Hello, flo.gehrke; Sunday, May 13, 2012, 12:47:23 PM, you wrote: fg The only drawback is that we still have to create an output file. fg Is there no way to
        Message 3 of 16 , May 13, 2012
          Hello, flo.gehrke;

          Sunday, May 13, 2012, 12:47:23 PM, you wrote:

          fg> The only drawback is that we still have to create an output file.
          fg> Is there no way to redirect the output from GAWK to the clipboard,
          fg> for example, without saving it to the disk?

          As I understand it, default AWK behaviour is to expect input from
          standard input, i.e. keyboard, and output to standard output, i.e.
          screen. Both can be redirected. I don't know a way to redirect STDOUT
          to the clipboard, which sounds like it should be the function of an
          obscure utility program. However,if you *were* willing to print to a
          file, you could send the contents of the file to the clipboard with a
          utility program, of which several exist. Recent versions of Windows -
          well, the Vista Home Premium I'm using, at least - ship with a
          Microsoft tool called CLIP.EXE to do this. I normally use Horst
          Schaeffer's freeware CLIPTEXT,
          http://www.horstmuc.de/wbat32.htm#cliptext because it can transfer
          between a file and the clipboard in *both* directions.

          Then you'd do something like

          gawk.exe -f script.awk foo.bar > c:\temp\gawkout.txt
          cliptext from c:\temp\gawkout.txt

          but that's getting more like a batch file, and maybe complicating the clip.

          --
          Regards,

          Robert Bull
          mailto:barlennan@...
        • flo.gehrke
          ... Robert, Thanks for your proposal. However, the point is NOT to print to a file. Also, I think there s no need to look for an utility programm for sending
          Message 4 of 16 , May 13, 2012
            --- In ntb-scripts@yahoogroups.com, Robert Bull <barlennan@...> wrote:
            >
            > Sunday, May 13, 2012, 12:47:23 PM, you wrote:
            >
            > The only drawback is that we still have to create an output file.
            > Is there no way to redirect the output from GAWK to the clipboard,
            > for example, without saving it to the disk?
            > (...) I don't know a way to redirect STDOUT to the clipboard,
            > which sounds like it should be the function of an
            > obscure utility program. However,if you *were* willing to print to a
            > file, you could send the contents of the file to the clipboard
            > with a utility program, of which several exist...

            Robert,

            Thanks for your proposal. However, the point is NOT to print to a file.

            Also, I think there's no need to look for an utility programm for sending file contents to clipboard. Why don't you use...

            ^!SetClipboard ^$GetFileText(output.txt)$

            In the meantime, I searched the web for more ideas that could help in this matter.

            It seems to be a common solution to redirect the GAWK output to the clipboard using CLIP.EXE as a pipe. This is a console utility that is used to copy text from the stream stdin to the windows clipboard. The data can then be pasted directly into a Windows application.

            So I installed CLIP.EXE in C:\Windows\System32\ and changed Kees' script as follows:


            BEGIN{
            # init code
            max = 0
            command = "clip"
            }
            # echo input to original file
            {
            print
            }
            (length($0) > max){
            max = length($0)
            }
            END{
            print max | command }


            I installed this script in a clipbook as a subclip named 'OutToClip'. Now I call this script with...

            ^!RunGawk OutToClip
            ^!Info ^$GetClipboard$

            and the result is perfectly displayed in an infobox -- without sending the result to an output file!

            This gets pretty close to my intention. The only problem with this is that it still changes the active document by reading and re-inserting its contents.


            Regards,
            Flo
          • mycroftj
            ... OK. I ve spent all morning trying to come up with a solution. I ve never done this before and have a few questions to work through on my journey. Why does
            Message 5 of 16 , May 14, 2012
              --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
              >
              > Hi GAWK experts!
              >
              > I can clearly see how to run a GAWK script from a NT clip. But I get into trouble whith redirecting GAWK output to a clip. Example:
              >
              > Given some lines...
              >
              > Adelaide
              > Adria
              > Karkonjafarabadi
              > Karolyne
              > Rob
              >
              > In my naive view, there should be a solution that redirects the GAWK result directly to the clipboard or a variable so the clip could call the result from there.
              >
              > Thanks for advice!
              >
              > Flo
              >


              OK. I've spent all morning trying to come up with a solution.
              I've never done this before and have a few questions to work through on my journey.


              Why does using GetOutput give me the "fstat < 0: fd = 0" line where as GetInputOutput does not?

              Why does running the GAWK code in a NT clip execute the PRINT statement but calling external files with GetOutput, GetInputOutput or running from DOS does not? (They just give me the output 16 and not the data lines in the input file.)

              Why does END { print max | command } work (when setting 'command' to 'clip' in BEGIN but END { print max | clip } does not work??



              C:\Program Files (x86)\GnuWin32\bin\gawk.exe
              C:\Program Files (x86)\NoteTab Light\Scripts\script.awk
              C:\Users\user\Documents\input.txt

              Entering this in DOS returns 16
              gawk.exe -f "C:\Program Files (x86)\NoteTab Light\Scripts\script.awk" "C:\Users\user\Documents\input.txt"

              Running this clip
              ^!Info ^$GetOutput(^$GetGawkExe$ -f "^$GetScriptPath$script.awk" "^$GetDocumentPath$input.txt")$
              gives me
              fstat < 0: fd = 0
              16
              Why don't I see the lines output by PRINT?


              Running this clip
              ^!Info ^$GetInputOutput(^$GetGawkExe$ -f "^$GetScriptPath$script.awk" "^$GetDocumentPath$input.txt")$
              gives me
              16
              Why don't I see the lines output by PRINT?


              GAWK Subroutine called in NT clip:
              This leaves all the original document lines followed by 16 on the last line. All text is selected by clip.
              # Find size of longest line
              {
              print $0
              if (length($0) > max) { max = length($0) }
              }
              END { print max }


              SCRIPT.AWK
              ----------
              # Find size of longest line
              {
              PRINT $0
              if (length($0) > max) { max = length($0) }
              }
              END { print max }


              INPUT.TXT
              ---------
              Adelaide
              Adria
              Karkonjafarabadi
              Karolyne
              Rob

              Thanks,
              Joy
            • mycroftj
              ... Did you ever get an answer to this part of this problem??? I think the problem here is the missing -f in the InsertText statement. Looks like it should
              Message 6 of 16 , May 14, 2012
                --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                >
                ---snip
                >
                > ;[path to exe]
                > ^!Set %lua%=
                > ;[path to the script]
                > ^!Set %script%=
                > ;[text to process, e.g. ^$GetSelection$, ^$GetClipboard$]
                > ^!Set %input%=
                > ^!InsertText ^$GetOutput(^%lua% "^%script%" "^%input%")$
                >
                > I tried to reproduce this with GAWK but I can't get it to work. For me, GAWK doesn't seem to accept the input from that ^%input% variable.
                >
                > It works when getting the input from a file:
                >
                > ^!Info ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^$GetDocumentPath$input.txt)$
                ---snip
                > Regards,
                > Flo
                >

                Did you ever get an answer to this part of this problem???
                I think the problem here is the missing '-f' in the InsertText statement. Looks like it should be
                ^!InsertText ^$GetOutput(^%lua% -f "^%script%" "^%input%")$

                Joy
              • flo.gehrke
                ... Joy, diodeom described a working solution with Lua. IMHO, we can t speak of a missing -f in the InsertText statement : In diodeom s model, the input
                Message 7 of 16 , May 14, 2012
                  --- In ntb-scripts@yahoogroups.com, "mycroftj" <mycroftj@...> wrote:
                  >
                  > --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@> wrote:
                  > >
                  > ---snip
                  > >
                  > > ;[path to exe]
                  > > ^!Set %lua%=
                  > > ;[path to the script]
                  > > ^!Set %script%=
                  > > ;[text to process, e.g. ^$GetSelection$, ^$GetClipboard$]
                  > > ^!Set %input%=
                  > > ^!InsertText ^$GetOutput(^%lua% "^%script%" "^%input%")$
                  > >
                  > > I tried to reproduce this with GAWK but I can't get it to work.
                  > > For me, GAWK doesn't seem to accept the input from that ^%input%
                  > > variable.
                  > >
                  > > It works when getting the input from a file:
                  > >
                  > > ^!Info ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^$GetDocumentPath$input.txt)$
                  > ---snip
                  > > Regards,
                  > > Flo
                  > >
                  >
                  > Did you ever get an answer to this part of this problem???
                  > I think the problem here is the missing '-f' in the InsertText statement. Looks like it should be
                  > ^!InsertText ^$GetOutput(^%lua% -f "^%script%" "^%input%")$
                  >
                  > Joy
                  >

                  Joy,

                  diodeom described a working solution with Lua. IMHO, we can't speak of a "missing '-f' in the InsertText statement": In diodeom's model, the input doesn't come from a file but is assigned to an %Input% variable (with ^$GetSelection$ or ^$GetClipboard$).

                  The problem is that we cannot apply this model to GAWK (called with NT) because we cannot use a variable as an argument in ^$GetOutput$ in a way like...

                  ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^%Input%)$

                  -- unless anyone explains how to achieve that.

                  I hope we'll get some replies to all your questions in message #555.

                  In my latest message, I described how to redirect the GAWK output TO the clipboard. So, for your own studies, it might interest you that there's also a way to get the input FROM the clipboard. See...

                  http://groups.google.com/group/comp.lang.awk/browse_thread/thread/35fe58692e3ae4fa/ff3ac224c1e6afae?lnk=gst&q=clipboard

                  If we could get this to work in a NT clip then it should be even possible to adjust diodeom's model to GAWK/NT.

                  Flo
                • Robert Bull
                  Hello, flo.gehrke; Sunday, May 13, 2012, 10:56:52 PM, you wrote: fg Also, I think there s no need to look for an utility programm for fg sending file
                  Message 8 of 16 , May 14, 2012
                    Hello, flo.gehrke;

                    Sunday, May 13, 2012, 10:56:52 PM, you wrote:

                    fg> Also, I think there's no need to look for an utility programm for
                    fg> sending file contents to clipboard. Why don't you use...

                    fg> ^!SetClipboard ^$GetFileText(output.txt)$

                    I didn't know that feature. Partly because I'm a long-term, if
                    not expert, AWK user, I've fought shy of learning more than the
                    absolute minimum of clipbook language...

                    [...]

                    fg> The only problem with this is that it still changes the active
                    fg> document by reading and re-inserting its contents.

                    If there isn't a solution, is it possible to make a workaround by
                    making the last line of the clip

                    ^!Keyboard CTRL+Z

                    i.e., once the AWK script has overwritten your original text, restore
                    it with Undo, and then paste from the clipboard?


                    I find it confusing when people talk about "clips"in Notetab, in that
                    it's not always clear whether an entry in the NT clipbook is meant, or
                    a clip in the sense of something copied or cut to the clipboard.

                    --
                    Regards,

                    Robert Bull
                    mailto:barlennan@...
                  • mycroftj
                    ... Accchh. Sorry about that. You are correct about the -f. I did see the input was from a variable then forgot later on. Between testing different versions of
                    Message 9 of 16 , May 14, 2012
                      --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                      >
                      > --- In ntb-scripts@yahoogroups.com, "mycroftj" <mycroftj@> wrote:
                      > >
                      > > --- In ntb-scripts@yahoogroups.com, "flo.gehrke" <flo.gehrke@> wrote:
                      > > >
                      > > ---snip
                      > > >
                      > > > ;[path to exe]
                      > > > ^!Set %lua%=
                      > > > ;[path to the script]
                      > > > ^!Set %script%=
                      > > > ;[text to process, e.g. ^$GetSelection$, ^$GetClipboard$]
                      > > > ^!Set %input%=
                      > > > ^!InsertText ^$GetOutput(^%lua% "^%script%" "^%input%")$
                      > > >
                      > > > I tried to reproduce this with GAWK but I can't get it to work.
                      > > > For me, GAWK doesn't seem to accept the input from that ^%input%
                      > > > variable.
                      > > >
                      > > > It works when getting the input from a file:
                      > > >
                      > > > ^!Info ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^$GetDocumentPath$input.txt)$
                      > > ---snip
                      > > > Regards,
                      > > > Flo
                      > > >
                      > >
                      > > Did you ever get an answer to this part of this problem???
                      > > I think the problem here is the missing '-f' in the InsertText statement. Looks like it should be
                      > > ^!InsertText ^$GetOutput(^%lua% -f "^%script%" "^%input%")$
                      > >
                      > > Joy
                      > >
                      >
                      > Joy,
                      >
                      > diodeom described a working solution with Lua. IMHO, we can't speak of a "missing '-f' in the InsertText statement": In diodeom's model, the input doesn't come from a file but is assigned to an %Input% variable (with ^$GetSelection$ or ^$GetClipboard$).
                      >
                      > The problem is that we cannot apply this model to GAWK (called with NT) because we cannot use a variable as an argument in ^$GetOutput$ in a way like...
                      >
                      > ^$GetOutput(^$GetGawkExe$ -f ^$GetScriptPath$script.awk ^%Input%)$
                      >
                      > -- unless anyone explains how to achieve that.
                      >
                      > I hope we'll get some replies to all your questions in message #555.
                      >
                      > In my latest message, I described how to redirect the GAWK output TO the clipboard. So, for your own studies, it might interest you that there's also a way to get the input FROM the clipboard. See...
                      >
                      > http://groups.google.com/group/comp.lang.awk/browse_thread/thread/35fe58692e3ae4fa/ff3ac224c1e6afae?lnk=gst&q=clipboard
                      >
                      > If we could get this to work in a NT clip then it should be even possible to adjust diodeom's model to GAWK/NT.
                      >
                      > Flo
                      >

                      Accchh. Sorry about that. You are correct about the -f. I did see the input was from a variable then forgot later on. Between testing different versions of clips, external subs, running GAWK from DOS, learning GAWK syntax, etc. I was getting quite dizzy.

                      I did see that message you referenced but didn't try it. Did you? At this point, I'm feeling the best way is to use your original code or, if it is applicable, my solution of echoing all the lines back out with the results as the last line.

                      This is Windows, not UNIX and unless you have a good reason (which I'm sure you do) the solution you are looking for might be more effort than it is worth for most situations.

                      I haven't given up. Ideas do come to me in the middle of the night.

                      Joy
                    • flo.gehrke
                      ... Robert, Yes, ^!Keyboard CTRL+Z or ^!Toolbar Undo is a good workaround -- at least in this specific example. Nevertheless, I m looking forward to see a
                      Message 10 of 16 , May 14, 2012
                        --- In ntb-scripts@yahoogroups.com, Robert Bull <barlennan@...> wrote:
                        >
                        > fg> The only problem with this is that it still changes the active
                        > fg> document by reading and re-inserting its contents.
                        >
                        > If there isn't a solution, is it possible to make a workaround by
                        > making the last line of the clip
                        >
                        > ^!Keyboard CTRL+Z
                        >
                        > i.e., once the AWK script has overwritten your original text,
                        > restore it with Undo, and then paste from the clipboard?

                        Robert,

                        Yes, '^!Keyboard CTRL+Z' or '^!Toolbar Undo' is a good workaround -- at least in this specific example.

                        Nevertheless, I'm looking forward to see a solution where a selection from the active document is copied to the clipboard and GAWK is taking the contents of the clipboard as input data -- see my latest reply to Joy with that link to comp.lang.awk.

                        Could you show us how to implement that procedure to our sample clip?

                        Regards,
                        Flo
                      • Robert Bull
                        Hello, flo.gehrke; Monday, May 14, 2012, 11:53:02 PM, you wrote: fg Nevertheless, I m looking forward to see a solution where a fg selection from the active
                        Message 11 of 16 , May 16, 2012
                          Hello, flo.gehrke;

                          Monday, May 14, 2012, 11:53:02 PM, you wrote:

                          fg> Nevertheless, I'm looking forward to see a solution where a
                          fg> selection from the active document is copied to the clipboard and
                          fg> GAWK is taking the contents of the clipboard as input data -- see
                          fg> my latest reply to Joy with that link to comp.lang.awk.

                          fg> Could you show us how to implement that procedure to our sample
                          fg> clip?

                          I can't see you last message to Joy. Is it in one of the other NT
                          groups?


                          Let me go back to the beginning and ask what you're trying to achieve.
                          Are you:

                          1) Making tests to help in understanding how NTP's clipbook interacts
                          with the Windows clipboard? If so, I don't know enough clipbook
                          programming to be able to help.

                          2) Wanting to open the file of words in NTP, run the AWK script on it
                          to find the maximum line length, and, leaving the original text
                          unchanged, append the max line length information to it? If so, I
                          think I know how to do that, and further think you're making it too
                          complicated.

                          Kees' script does the job. What I've done is put my version of it
                          (pedantically modified to make it clearer to me) in a NTP "script
                          clip" (my name for it), and call it from another "real clip." I have
                          a section titled Scripts in my clipbook, beneath the section of
                          ordinary clips. In the Scripts section I have a clip entitled "Kees
                          AWK script". It contains my version of Kees' script:

                          Kees AWK script
                          ----------------
                          BEGIN { max = 0 + 0 }
                          # echo input to original file
                          {
                          print
                          }
                          # the rest of the script
                          {
                          if(length($0) > max){
                          max = length($0)
                          }
                          }
                          END { printf("max line length is %d", max) }
                          ----------------
                          Notice there aren't any references to files or file names at all.

                          The clip that calls this script has to be called by another name -
                          very important - here it's "Test - Kees", containing just the calling
                          line:

                          Test - Kees
                          ----------------
                          ^!RunGawk "Kees AWK script"
                          ----------------

                          When I have your test data open in an NTP file and run the "Test -
                          Kees" clip *making sure to avoid calling "Kees AWK script" by name, I
                          get:

                          ----------------
                          Adelaide
                          Adria
                          Karkonjafarabadi
                          Karolyne
                          Rob
                          max line length is 16
                          ----------------

                          To prove it, I made a Jing Screencast video that you can see at
                          http://screencast.com/t/TW7PYAbQL9

                          Note that I usually activate clips by pressing Esc and choosing from
                          the dropdown menu. I'd already tested the clip, so the lightbar is
                          already on the required clip.

                          Apologies if I have still misunderstood what you were looking for.

                          --
                          Regards,

                          Robert Bull
                          mailto:barlennan@...
                        • flo.gehrke
                          ... Thanks, Robert! I see that last version working and getting to the result that you had in mind. Actually, I never talked of inserting the result into the
                          Message 12 of 16 , May 17, 2012
                            --- In ntb-scripts@yahoogroups.com, Robert Bull <barlennan@...> wrote:
                            >
                            > Kees' script does the job (...) I have a section titled Scripts in
                            > my clipbook, beneath the section of ordinary clips. In the Scripts
                            > section I have a clip entitled "Kees AWK script". It contains my
                            > version of Kees' script:
                            >
                            > Kees AWK script
                            > ----------------
                            > BEGIN { max = 0 + 0 }
                            > # echo input to original file
                            > {
                            > print
                            > }
                            > # the rest of the script
                            > {
                            > if(length($0) > max){
                            > max = length($0)
                            > }
                            > }
                            > END { printf("max line length is %d", max) }
                            > ----------------
                            > Notice there aren't any references to files or file names at all.

                            Thanks, Robert!

                            I see that last version working and getting to the result that you had in mind.

                            Actually, I never talked of inserting the result into the active document. The goal was...

                            - To have that list (source text) open

                            - to run a clip which calls GAWK and starts a GAWK script which calculates the length of the longest line

                            - to redirect the result from GAWK back into the NT clip

                            - to continue clip execution with that data, i.e., in this case, just the value '16'.

                            In this context, I mentioned the clipboard only as a target for redirecting the GAWK output. The idea was, to continue clip execution, for example, with displaying the result in an infobox that could call the clipboard with...

                            ^!Info The longest line has ^$GetClipboard$ characters

                            Meanwhile, we saw approaches how to redirect the GAWK output to the clipboard (with MS Clip.exe). Also, how to direct the input into GAWK from the clipboard (with gclip.exe from UnxUtils). This could be of interest in cases where we send data from NT to the clipboard, process them with GAWK, and redirect the result via the clipboard back into a clip execution.

                            So far, we didn't see a solution for this redirection (to clipboard/from clipboard). That's why I remembered my message #557.

                            If you still have the patience to spend some time with that subject -- please have a look at the latest messages. It's all in the NT Scripts Group on Yahoo -- or in your incoming emails ;-)

                            Regards,
                            Flo
                          • Robert Bull
                            Hello, flo.gehrke; Thursday, May 17, 2012, 8:17:01 PM, you wrote: fg I see that last version working and getting to the result that you fg had in mind. What
                            Message 13 of 16 , May 17, 2012
                              Hello, flo.gehrke;

                              Thursday, May 17, 2012, 8:17:01 PM, you wrote:

                              fg> I see that last version working and getting to the result that you
                              fg> had in mind.

                              What a pity it wasn't what *you* had in mind. I might have known I'd
                              get the wrong end of the stick... still, it was a fun play session.


                              --
                              Regards,

                              Robert Bull
                              mailto:barlennan@...
                            • Kees Nuyt
                              ... PRINT is not the same as print . gawk is case-sensitive. -- Regards, Kees Nuyt
                              Message 14 of 16 , May 17, 2012
                                On Mon, 14 May 2012 16:17:09 -0000, you wrote:

                                > Why don't I see the lines output by PRINT?
                                >
                                >
                                > GAWK Subroutine called in NT clip:
                                > This leaves all the original document lines followed by 16 on the last line. All text is selected by clip.
                                > # Find size of longest line
                                > {
                                > print $0
                                > if (length($0) > max) { max = length($0) }
                                > }
                                > END { print max }
                                >
                                >
                                > SCRIPT.AWK
                                > ----------
                                > # Find size of longest line
                                > {
                                > PRINT $0
                                > if (length($0) > max) { max = length($0) }
                                > }
                                > END { print max }

                                PRINT is not the same as print .
                                gawk is case-sensitive.


                                --
                                Regards,

                                Kees Nuyt
                              Your message has been successfully submitted and would be delivered to recipients shortly.