You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Skipping N lines of a large file, then piping #6570
That file is huge, so I can't load it all into memory -- but there should be no need for that, unless pipelines are entirely sequential and store the intermediate result. Although nushell supports an impressive array of inputs, including SQLite, it doesn't seem to support any compressed formats natively (right?). So first I extracted my .gz into its own file. Then, I have tried:
> open --raw filename.sql | lines | skip 46 | to text | mysql dbname
This appears to load everything into memory.
If I do:
open --raw pagelinks.sql | lines | skip 47 | take 1 | to text | mysql dbname
it seems to work, but that of course only gets one line. Can nushell do streaming like I need? I am sorry I was unable to find the docs but I read the entire book and cookbook. I'm really impressed with nushell generally but couldn't figure out this simple script. Thanks for your help in advance!
As @fdncred said, the to text is the main problem that prevents streaming, since you are essentially telling it to collect the entire list of lines/strings into a single string.
zcat filename.sql.gz | lines | skip 46| each { mysql dbname }
... should work. It definitely works for me in a 20 million line test file using the form:
Activity
fdncred commentedon Sep 16, 2022
I'm trying to understand what you're doing and may not be getting it all.
If I do this:
it seems to stream the rest of the data.
to textabsolutely does acollectso it will not stream.You could try
print- i can't remember if it collects or not (I don't think it does), like:NotTheDr01ds commentedon Sep 16, 2022
Repeating my Super User answer to your question there.
As @fdncred said, the
to textis the main problem that prevents streaming, since you are essentially telling it to collect the entire list of lines/strings into a single string.... should work. It definitely works for me in a 20 million line test file using the form:
Alternatively, using explicit output and an explicit
eachvariable:NotTheDr01ds commentedon Sep 16, 2022
Dang Cool -- I didn't realize we have
nuas a language specifier on code-blocks here!hut8 commentedon Sep 16, 2022
Perfect. Thanks for the help!
fdncred commentedon Sep 16, 2022
@NotTheDr01ds
nuis a language recognized by GitHub that isn't nushell, unfortunately.NotTheDr01ds commentedon Sep 16, 2022
Ah, that makes sense. Thanks. I got excited when it did a passable job at formatting ...