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

549Re: [NTS] Redirecting GAWK Output

Expand Messages
  • Kees Nuyt
    May 12, 2012
    • 0 Attachment
      On Thu, 10 May 2012 12:13:53 -0000, you 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...
      >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!

      The canonical way to keep the list intact is to always include a print

      # init code
      max = 0
      outfile = "/path/to/your/output/filename.txt"
      # echo input to original file
      # the rest of the script
      (length($0) > max){
      max = length($0)

      # choose one of these output options:
      print max >outfile # overwrite outfile
      print max >>outfile # append to outfile

      As the next step, the clip can pickup the output file.

      Hope this helps.


      Kees Nuyt
    • Show all 16 messages in this topic