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

Make eawk accept a custom separator #1728

Merged
merged 4 commits into from
Dec 27, 2023

Conversation

saolof
Copy link
Contributor

@saolof saolof commented Oct 12, 2023

One of the biggest pain points of using elvish as a shell in practice for
me has been parsing output from shell commands that return text.

Many CLIs are parseable by AWK. Elvish provides eawk to provide
some of the key tasks that AWK does without introducing a
separate DSL, relying solely on the expressiveness of lambdas.

In practice, most of the power of AWK is being able to change
the separator to parse the particular output of the command
you pipe into it (commas, pipe, spacing strictly longer than two spaces, etc etc).
So this commit adds an optional sep argument that takes a regex pattern.

(I also updated the dockerfile.)

One of the biggest pain points of using elvish
as a shell in practice has been parsing output from
shell commands that return text.

Many CLIs are parseable by AWK. This commit
adds the AWK separator argument to eawk,
which should make it easier to parse the
output of many shell commands.
@krader1961
Copy link
Contributor

It's great seeing someone new take the time to create a pull-request. But you also need to update the unit test to verify the new functionality. See the TestEawk function in builtin_fn_str_test.go.

@saolof
Copy link
Contributor Author

saolof commented Oct 12, 2023

Yes, I am putting together a couple of examples. I think sample outputs from psql and from docker image ls should work?

@saolof
Copy link
Contributor Author

saolof commented Oct 14, 2023

@krader1961 Added the docker image ls test.

@xiaq xiaq changed the base branch from master to merge-eawk-sep December 27, 2023 23:47
@xiaq
Copy link
Member

xiaq commented Dec 27, 2023

Thanks for the contribution.

I find the name of the options (&sep and &posix) potentially confusing though. It's not clear that &sep should be a regular expression (instead of a literal string to pass to str:split) and that &posix refers to the syntax of the regular expression.

I think it's best to move the command into the re: module altogether and have it named re:awk instead - the option names becomes unambiguous this way. The eawk name can remain now as a deprecated alias and be removed later.

I'll merge this to a temporary branch which I'll integrate to master later.

Maybe a re:sed is also in order...

@xiaq xiaq merged commit 495f427 into elves:merge-eawk-sep Dec 27, 2023
0 of 4 checks passed
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

Successfully merging this pull request may close these issues.

3 participants