Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output format #104

Open
muzzol opened this issue Jun 30, 2022 · 12 comments
Open

Output format #104

muzzol opened this issue Jun 30, 2022 · 12 comments

Comments

@muzzol
Copy link

muzzol commented Jun 30, 2022

This is a feature request for output format configuration.

I would like to remove ending ";" from lines and also remove spaces before and after "=" so instead of this:

json.message.chat.id = 7403466;

I got this

json.message.chat.id=7403466

I think this way will be a lot easier to parse results:

cat test.json | grep "json.message.chat.id" | cut -d"=" -f2

instead of

cat test.json | grep "json.message.chat.id" | cut -d"=" -f2 | cut -d" " -f2- | tr -d";"

@mnhrdt
Copy link

mnhrdt commented Jun 30, 2022

Closely related, there could be an option also for removing the useless lines ending with "= {};" and "= [];". That would make it even more grepable!

@RossPatterson
Copy link

I would like to remove ending ";" from lines and also remove spaces before and after "=" so instead of this:
...
cat test.json | grep "json.message.chat.id" | cut -d"=" -f2

If you're going to pipe the output anyway, why not just run it through sed -e "s/ = /=/" -e "s/;$//" to get the format you like?

@RossPatterson
Copy link

Closely related, there could be an option also for removing the useless lines ending with "= {};" and "= [];". That would make it even more grepable!

They're not useless. They may the output correct JSON.

@mnhrdt
Copy link

mnhrdt commented Jul 1, 2022

They're not useless. They may the output correct JSON.

Sure, but sometimes you don't care about that. The same option could remove the semicolons, these "empty" lines, and even the equal signs altogether (so that the output is, from the unix point of view, just two columns of NAME VALUE pairs). As @muzzol , often I also spend a lot of sed and awk just to remove this clutter before processing it further.

If this option is easy to add, it would be nice to have.

@gibson042
Copy link

Piling on, it would be nice to have a mode with guaranteed consistency for how keys are represented. That is, quoting all of them rather than on those that are not identifiers.

 json = {};
-json.Host = "headers.jsontest.com";
+json["Host"] = "headers.jsontest.com";
 json["User-Agent"] = "gron/0.1";
 json["X-Cloud-Trace-Context"] = "6917a823919477919dbc1523584ba25d/11970839830843610056";

@mnhrdt
Copy link

mnhrdt commented Oct 19, 2022

quoting all of them

But wouldn't this make the output less greppable in general? I'd rather have all keys without quotes, regardless of whether they are identifiers or not.

@gibson042
Copy link

@mnhrdt
Copy link

mnhrdt commented Oct 20, 2022

That would violate "The output of gron is valid JavaScript"

Sure, and because of this reason the simplified output should not be the default behavior of gron. Still, there may be some value in providing a "super-greppable" uncluttered output for when you don't care that the output is valid javascript (e.g., inside a shell pipeline). For example, I'd like to have an output that looks just like this :

Host headers.jsontest.com
User-Agent gron/0.1
X-Cloud-Trace-Context 6917a823919477919dbc1523584ba25d/11970839830843610056

that is, a text file with two columns that can be directly processed by the standard unix utilities.

@muzzol
Copy link
Author

muzzol commented Oct 20, 2022

Sure, and because of this reason the simplified output should not be the default behavior of gron. Still, there may be some value in providing a "super-greppable" uncluttered output for when you don't care that the output is valid javascript

exactly this.
creating simple bash scripts is one of the reasons I choose this tool, it's not really important if origin is a regulated standard or just a line of text.

@muzzol
Copy link
Author

muzzol commented Oct 20, 2022

just to give some context, here's the help for smbclient utility:

smbclient --help
Usage: smbclient service <password>
  -R, --name-resolve=NAME-RESOLVE-ORDER     Use these name resolution services only
  -M, --message=HOST                        Send message
  -I, --ip-address=IP                       Use this IP to connect to
  -E, --stderr                              Write messages to stderr instead of stdout
  -L, --list=HOST                           Get a list of shares available on a host
  -m, --max-protocol=LEVEL                  Set the max protocol level
  -T, --tar=<c|x>IXFvgbNan                  Command line tar
  -D, --directory=DIR                       Start from directory
  -c, --command=STRING                      Execute semicolon separated commands
  -b, --send-buffer=BYTES                   Changes the transmit/send buffer
  -t, --timeout=SECONDS                     Changes the per-operation timeout
  -p, --port=PORT                           Port to connect to
  -g, --grepable                            Produce grepable output
  -q, --quiet                               Suppress help message
  -B, --browse                              Browse SMB servers using DNS

notice the '-g' option: -g, --grepable Produce grepable output

@gibson042
Copy link

What if a property name includes the delimiter sequence?

@mnhrdt
Copy link

mnhrdt commented Oct 22, 2022

What if a property name includes the delimiter sequence?

Then the output would be slightly ambiguous, but still easily grepable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants