TACL Filtering results from a history command

305 views Asked by At

I have been trying to think of solutions for this but have not had much luck on my own.

I am trying to create a macro/routine that will filter out certain results from the system as we normally get flooded by them.

Is there a way to filter results that contain 512345 or any other numbers.

I have thought about maybe outputting the history results into a file and then making some sort of loop to read said file and try filter it out that way but i don't even know how to do that as I have no examples to work off of.

This is the current history command i'm trying to use.

History all,,substandard approval rate

Any ideas/help would be great;y appreciated

Thanks.

3

There are 3 answers

0
NightHeron On

I very recently wrote a ?tacl routine to display commands which match a given string and allows you to choose one for re-execution; it's not well tested and also does not mimic FC, i.e. allow you to edit the command prior to running it.

My apologies for any bugs or awkwardness; My non-stop skills are a bit rusty.

    ?section incr routine
    #frame
    #push var_to_incr
    [#loop |while| [#more] |do|
      sink [#argument /text var_to_incr/ variable /syntax/]
      #set [var_to_incr] [#compute [var_to_incr] + 1]
    ]
    #unframe


    ?section isdigit routine
    #frame
    push var off ch nope
    #set off 1
    #set nope 12345678
    #set var [#rest]
    [#loop |while| [off] <= [#charcount var] |do|
      #set ch [#charget var [off] for 1]
      [#CASE [ch]
        | 0 |
        | 1 |
        | 2 |
        | 3 |
        | 4 |
        | 5 |
        | 6 |
        | 7 |
        | 8 |
        | 9 |
        | OTHERWISE |
          #set off [#compute [nope]-1]
      ]
      incr off
    ]

    [#if [off] = [nope] |then|
      #result 0
    |else|
      #result 1
    ]
    #unframe


    ?section tmpfile routine

    push tmpfile^tdir tmpfile^tfil tmpfile^cmds

    [#if [#more] |then|   == have args
      #if [#argument /value tmpfile^tdir/ word /space/]
      [#set tmpfile^tdir [tmpfile^tdir].]
    ]

    #SET/TYPE DELTA/tmpfile^cmds 0,Z-4K
    [ #LOOP |DO|
      #SET tmpfile^tfil [tmpfile^tdir]z6[ #DELTA/COMMANDS tmpfile^cmds/
      [#TIMESTAMP] ]
      |UNTIL| NOT
      [ #FILEINFO/EXISTENCE/ [tmpfile^tfil ]]
    ]

    #result [tmpfile^tfil]
    pop tmpfile^tfil tmpfile^tdir tmpfile^cmds


    ?section selhist routine

    == get optional search arg
    push argv
    #if [#argument/peek, text argv/text otherwise]
    [#if "[argv]" '<>' "" |then|
      #if [#argument/text argv/word]   == get it
    ]

    == get history
    push tfil hist
    #set tfil [tmpfile [tmpdir]]
    push #out
    #set #out [tfil]
    history 100
    pop #out
    filetovar [tfil] hist

    == display history
    push cmd fvar
    [#loop |while| not [#emptyv hist] |do|
      #extractv hist cmd
      [#set fvar]
      [#if not [#emptyv cmd] |then|
        [#if "[argv]" '<>' "" |then|
          vfind/quiet, to fvar/ cmd "[argv]"
        |else|
          [#set fvar [cmd]]
        ]
        [#if "[fvar]" '<>' "" |then|
          #output [cmd]
          push ohist
          [#set ohist [cmd]]
        ]
      ]
    ]

    push sel
    [#set sel]
    #inputv sel   "Which command: "
    [#if "[sel]" '<>' "" AND [isdigit [sel]] |then|
      == choice made -- find and reexcute it
      [#set sel [sel]>]
      push lenof
      [#set lenof [#charcount sel]]
      [#loop |while| [#variableinfo/existence/ ohist] |do|
        [#set cmd [#charget ohist 1 for [lenof]]]
        [#if "[cmd]" '=' "[sel]" |then|
          incr lenof
          [#set cmd [#charget ohist [lenof] for [#charcount ohist]]]
          [cmd]
        ]
        pop ohist
      ]
      pop lenof
    |else|
      pop ohist
    ]

    pop argv
    remove [tfil]
    pop tfil
    pop hist
    pop cmd
    pop fvar
    pop sel
5
Andy Simpson On

The builtin TACL history command only accepts one (optional) argument which is the number of old commands to show you, so it's not obvious that you are using that from your example. It also uses #HISTORY which has a buffer of 1000 characters.

Assuming that you are using the builtin command, you can see how it is written and write your own TACL routine that does filtering. You would have to redirect #OUT to capture the output.
This is what the existing command looks like:

    $AS ASHOME 3> outvar history
    #FRAME
    #PUSH :^lines
    [#CASE [#ARGUMENT/VALUE :^lines/ NUMBER END]
    |1| [#IF [#ARGUMENT END]]
    |2| #SET :^lines 10
    ]
    #HISTORY/SHOW :^lines/
    #UNFRAME

So you can do something along these lines:


    $AS ASHOME 4> #PUSH #OUT
    $AS ASHOME 5> #SET #OUT a
    $AS ASHOME 6> #HISTORY/SHOW 100/
    $AS ASHOME 7> #POP #OUT
    $AS ASHOME 8> #PUSH cmds
    $AS ASHOME 9> FILETOVAR a cmds
    $AS ASHOME 10> #OUTPUTV cmds

You now have the history in file a and also in a TACL variable cmds and you can process it as you want.

0
hanisntsolo On

You see you can use the above explanation and store the logs in a variable and later filter that variable using appropriate filters to get the desired results.

If you are using an inline process, make sure to close the process before exiting or else it will interrupt saying an inline process already exists.