5

in grep command I can set max line to output with parameter -m. How I can specify max line in cat command ?

9

cat is dedicated to whole files.

You are looking for either head or tail, depending if your counting starts from the beginning or end of a file.

Examples

  • head --lines=100 print the first 100 lines
  • head --lines=-100 print all but the last 100 lines
  • tail --lines=100 print the last 100 lines
  • tail --lines=-100 print all but the first 100 lines

Note

You may also have a look at tac. The result is clear, if you compare the word tac with cat.
tac prints out all lines in reverse ordering.

  • I want to println file from start. Thx head is what I looking for – hudi Mar 12 '13 at 8:37
  • @hudi updated answer should make it clear. – user86064 Mar 12 '13 at 8:42
0

Use head -n $NUMBER_OF_LINES instead of cat.

And watch out for useless uses of cat.

  • @hudi: Read the answer again. – BatchyX Mar 12 '13 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.