Visidata: [cmdlog] Replay .vd but with different sources

Created on 25 May 2020  ·  9Comments  ·  Source: saulpw/visidata

Hi,
I have an html input file (tmp8.html), I open the results table inside it and I save this as results.tsv.

This is the the log

sheet   col row longname    input   keystrokes  comment
    SqliteSheet header  set-option  0       
    UsvSheet    delimiter   set-option  ␞       
    UsvSheet    row_delimiter   set-option  ␟       
            open-file   tmp8.html   o   
tmp8        キresults    dive-row        ^J  open sheet with copies of rows referenced in current row
results         save-sheet  results.tsv ^S  save current sheet to filename in format determined by extension (default .tsv)

Is there a way to use the log and apply it to an input file that has the same schema, but a different name? Do I must use the field option?

If my new html input file is tmp9.html, do I must run vd -p tmp8.vd sheet=tmp9? I think no, because in my log file the sheet field has two values, tmp8 and results, and I must find a way to say to vd to replace only the first.

I'm attaching the source html file, my log and my output.

Thank you

input.zip

question wishlist

Most helpful comment

Interesting question @aborruso - I've also wondered about reusing replay files. I like @frosencrantz's bash approach. That's neat :). One more VisiData-native option would be having a custom command in your ~/.visidatarc that opened a file based on a vd option. Then you could specify that option at runtime. For example, in ~/.visidatarc:

vd.option('replay_file', '', 'file to open during a replay')
globalCommand('', 'open-replay-file', 'vd.push(openSource(options.replay_file))')

In your *.vd replay file, you'd replace open-file tmp8.html with open-replay-file. And then when you run the replay:

vd --replay-file tmp8.html -p replay.vd

That covers the open-file part, but still leaves the question about what value to use in that first sheet column. Looks like if you leave the sheet name blank or use a 0 it'll run that row's command against the top sheet on the stack. Using 1 will run the command on the previous sheet, and so on.

So it seems like you could build a replay file with relative sheet references and not have any hardcoded sheet or file names. Worth a shot anyway :).

All 9 comments

If I understand, I have hit the same problem. My workaround was to use a shell script, with a heredoc (example below). It would be helpful if we could do the mapping via vd.

#!/bin/bash
TABLENAME=tmp8
cat <<EOF
sheet   col row longname    input   keystrokes  comment
    SqliteSheet header  set-option  0       
    UsvSheet    delimiter   set-option  ␞       
    UsvSheet    row_delimiter   set-option  ␟       
            open-file   tmp8.html   o   
${TABLENAME}        キresults    dive-row        ^J  open sheet with copies of rows referenced in current row
results         save-sheet  results.tsv ^S  save current sheet to filename in format determined by extension (default .tsv)
EOF

Interesting question @aborruso - I've also wondered about reusing replay files. I like @frosencrantz's bash approach. That's neat :). One more VisiData-native option would be having a custom command in your ~/.visidatarc that opened a file based on a vd option. Then you could specify that option at runtime. For example, in ~/.visidatarc:

vd.option('replay_file', '', 'file to open during a replay')
globalCommand('', 'open-replay-file', 'vd.push(openSource(options.replay_file))')

In your *.vd replay file, you'd replace open-file tmp8.html with open-replay-file. And then when you run the replay:

vd --replay-file tmp8.html -p replay.vd

That covers the open-file part, but still leaves the question about what value to use in that first sheet column. Looks like if you leave the sheet name blank or use a 0 it'll run that row's command against the top sheet on the stack. Using 1 will run the command on the previous sheet, and so on.

So it seems like you could build a replay file with relative sheet references and not have any hardcoded sheet or file names. Worth a shot anyway :).

Thank you very much @frosencrantz and @ajkerrigan !!

Then there is no way to use, for my goal, the {field} option.

It would be great to have a syntax as vd -b -p tmp8.vd sheet:2=tmp9 input:2=avalue so set field name and row number (here as example it's 2)

I am going to wishlist that request, @aborruso!

Thanks @frosencrantz and @ajkerrigan for answering the question thoroughly. <(^___^)>

thank you @anjakefala

When #521 will be solved, it will be very easy to write a script for this specific goal.

However I think that to have a way to use log file, passing parameter via cli, would give even more "power" to vd. Because the user could record a very specialized task, save it as a sort of macro and apply it to a lot of file; in many professions, there are often repeated tasks.

@aborruso Does this work for you now in 2.0? An empty sheet name or "0" should refer to the top sheet.

@aborruso Does this work for you now in 2.0? An empty sheet name or "0" should refer to the top sheet.

Please @saulpw help me: what's the new 2.0 syntax I can use to replay .vd but with different source?

Do I must edit my vd file and replace sheet name with null or 0?

Hi @saulpw! It works for me with 0 as the sheet name, though I still have to edit the open-file command with the new filename. Would it be possible to make it so that if a data file is provided on the command line, it just runs open-file on it before executing the command log? That way you could just remove the open-file line from your .vd file and run the script on any data.

Before digging into it, I intuitively thought that:

vd -p log.vd data.jsonl

would replay the log on the new file.

Please @saulpw help me: what's the new 2.0 syntax I can use to replay .vd but with different source?
Do I must edit my vd file and replace sheet name with null or 0?

Yes, that's the easiest way. Just blanking the sheet column should get the .vd to work on the 'top' sheet (and we should look into it, as @lxcode suggests that it doesn't right now).

Was this page helpful?
0 / 5 - 0 ratings