App-Rak icon indicating copy to clipboard operation
App-Rak copied to clipboard

Option to include the first line of any searched file in the output

Open MasterDuke17 opened this issue 2 years ago • 4 comments

I'm frequently searching CSV files with 20-30 columns, and when there's a hit it can be hard to know what the columns are. An option to print the first line of a file (either always, or only if that file had a match to the pattern) in addition to any hits would be nice.

MasterDuke17 avatar Aug 20 '23 18:08 MasterDuke17

Are you using --cvs-per-line for this?

In other words: I guess you'd only want the first line if it is a CSV file, right?

Or are you searching pure on text?

lizmat avatar May 09 '24 11:05 lizmat

I didn't know about/wasn't using --csv-per-line. I guess I generally know it's they're CSV files, but for some reason I'm thinking of the print-first-line as a general option.

MasterDuke17 avatar May 12 '24 23:05 MasterDuke17

Then I guess you'd only want that printed if there is actually a match anywhere in the file. Not just for all files that are being searched, right?

lizmat avatar May 13 '24 08:05 lizmat

How about a --accept-first[=N] option. This would accept the first N lines as matches (with N being 1 if specified as a flag).

This would then always show the first line of any file inspected.

lizmat avatar May 13 '24 14:05 lizmat

@MasterDuke17

So I'm thinking of adding:

--always-first[=N] This will basically not call the matcher for the first N lines (with N defaulting to 1), but will always produce them as if they matched.

--also-first[=N] This is basically a special type of context: if there is a match, it will produce the first N (with N defaulting to 1) as context.

Would that make sense?

lizmat avatar Aug 18 '24 18:08 lizmat

Yep, that's pretty much exactly what I was thinking.

MasterDuke17 avatar Aug 18 '24 19:08 MasterDuke17

Implemented with 0.3.9 so closing

lizmat avatar Aug 19 '24 10:08 lizmat