3

I am trying to modify a script so that it will truncate the output that goes to another file to a maximum (for example: 1000 lines).

I have read about split, but what I understand is that split by default does 1000 by default and splits that file into smaller files.

But, there may be a time when the output isn't going to be 1000 lines. It may only be 100.

I just want to cap the output at no more than X amount.

1 Answer 1

7

If you want to split the output into multiple files, each limited to 1000 lines, then use split.

If you just want to "truncate the output that goes to another file to a maximum (for example: 1000 lines)," then use head:

cmd | head -n1000 >output_file

The -n option tells head to limit the number of lines of output. Alternatively, to limit the output by number of bytes, the -c option would be used. For details, see man head.

The companion utility to head is tail. One uses tail when one wants the end of a file, rather the the beginning. Thus, tail -n1000 would deliver the last 1,000 lines of a file.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.