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

[feature request] select rightmost/trailing indices #57

Open
jskrzypek opened this issue Jun 17, 2022 · 2 comments
Open

[feature request] select rightmost/trailing indices #57

jskrzypek opened this issue Jun 17, 2022 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jskrzypek
Copy link

This might not be feasible, but I'd really like to be able to select rightmost/trailing fields from each line.
My use-case is for flattening an arbitrarily nested tree of files, where I only care about the parent directory and the filename of the files.

EX: Imagine this is the file structure

a
|-b
| |-c.jpg
| \-d
|   |-e.jpg
|   \-f.jpg
|-g
| |-h
| | \-i.jpg
| \-j.jpg
\-k.jpg

If I ran find ./a -type f -regex '.*\.jpg' on in the parent of a/ it would produce this output:

./a/b/c.jpg
./a/b/d/e.jpg
./a/b/d/f.jpg
./a/g/h/i.jpg
./a/g/j.jpg
./a/k.jpg

I want to generate the following output by selecting the 2 rightmost fiels from this input stream when splitting on / and joining on _ (i.e. quivalent to hck -d/ -D_ ...)

b_c.jpg
d_e.jpg
d_f.jpg
h_i.jpg
g_j.jpg
a_k.jpg

Would this be feasible? I can think of a couple signifiers for the potential option flag if it is, but my preference would be +f 2,1 (i.e. an inverted -f).

@sstadick
Copy link
Owner

Thanks for making an issue!

I think this should be doable - I don't have bandwidth to do this right this second, but will try to work it in at a future point.

(writing this out for future self of anyone inspired enough to do a PR)
Within hck there are a few different code-paths to parsing lines based on the parameters chosen, with different levels of optimization applied to each. An inverted -f will need its own set of codepaths, one for the regex delimiter and one for the substr literal delimiter that reverses the input string before splitting (or figure out how to .rev the split iterator. See https://github.com/sstadick/hck/blob/master/src/lib/line_parser.rs

It may be tricky to specify output order... but also doable.

@sstadick sstadick added enhancement New feature or request help wanted Extra attention is needed labels Jun 20, 2022
@jskrzypek
Copy link
Author

Doable is what I like to hear!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants