How to specify lines per file?

070

To specify a different number of lines for each file when using the tail command, you can use the -n option followed by the number of lines for each file separately. However, tail does not support specifying different line counts directly in a single command for multiple files. Instead, you need to run separate tail commands for each file.

Here’s how you can do it:

tail -n 5 file1.txt   # Display last 5 lines of file1.txt
tail -n 10 file2.txt  # Display last 10 lines of file2.txt
tail -n 3 file3.txt   # Display last 3 lines of file3.txt

If you want to combine the output into a single command, you can use a subshell or a script to achieve that, but it won't be a single tail command. Here's an example using a subshell:

{ tail -n 5 file1.txt; echo; tail -n 10 file2.txt; echo; tail -n 3 file3.txt; }

This will display the specified number of lines for each file in sequence.

0 Comments

no data
Be the first to share your comment!