I need to create a new file from a grep match but with maximum number of lines.
Something equivalent to this but one-liner
$ cat my_log_file.log | grep -v auto > filtered.log
$ head -n 1000 filtered.log > filtered_1000_lines.log
The answer is
$ grep -v auto -m 1000 my_log_file.log > filtered_1000_lines.log
Where -m NUM, --max-count is the maximum number of matched lines to stop the command, so the filtered_1000_lines.log will be feed with the first 1000 matched lines.
on one line
grep -v auto my_log_file.log | tail -1000 > filtered_log.log
(real solution is -m 1000 if grep allow it)
cat my_log_file.log | grep -v auto > filtered.log ; \
tail -n 1000 filtered.log > filtered_1000_lines.log
Either you can combine two commands (can be applied to more than 2 commands even) using && or ;
(above is written using ; combination)
grepsupport the-m NUM, --max-count=NUMoption?grep -v auto -m 1000 my_log_file.log > filtered_1000_lines.loggrep -v auto. More clarity is needed on what you are trying to do.head -n 1000 filtered.log > filtered_1000_lines.log