Coder Social home page Coder Social logo

Line by line parsing about jc HOT 7 CLOSED

mitar avatar mitar commented on June 10, 2024
Line by line parsing

from jc.

Comments (7)

kellyjonbrazil avatar kellyjonbrazil commented on June 10, 2024

Hi there!

Does this provide the expected output?


while true; do
  date | jc —date
  sleep 1
done

from jc.

mitar avatar mitar commented on June 10, 2024

Suure. But I do not control how is the stream of dates generates. That was just an example/reproduction to motivate this issue.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on June 10, 2024

Gotcha. I’d have to play around with it but can’t get to it for a few days - not sure if it’s possible in a stream you don’t control. There are a few parsers that support streams (like ping-s) but the date parser is not one of them.

You could implement a plugin parser (e.g. date-s. You could take a look at how the other streaming parsers are done and do something similar.

from jc.

mitar avatar mitar commented on June 10, 2024

No hurry. I think it would be nice if any plugin could be converted to a stream one by simply reapplying it again and again on the stream. But probably that would require from each plugin to have a concept of chunks.

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on June 10, 2024

That would definitely work for the parsers that work on a single line of text like date. Like you mentioned, would require more thought for other parsers.

from jc.

mitar avatar mitar commented on June 10, 2024

I got some inspiration from your blog post and made regex2json tool which allows conversion of test-based data into JSON by just providing a regex. So similar to how jc works, but for more ad-hoc use cases where you write the pattern as CLI argument. And it also operates on line-to-line. This I think nicely works together with the jc tool and other tools operating on JSON. I think piping JSON lines instead of text lines between processes is really powerful.

So the example above could then be:

$ while true; do LC_TIME=C date; sleep 1; done | regex2json "(?P<date___time__UnixDate__RFC3339>.+)"
{"date":"2023-06-13T11:26:45Z"}
{"date":"2023-06-13T11:26:46Z"}
{"date":"2023-06-13T11:26:47Z"}

from jc.

kellyjonbrazil avatar kellyjonbrazil commented on June 10, 2024

This is fantastic! Very cool tool. I’ll link to it in the readme in the next release.

from jc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.