Display line number in head and tail command like `cat -n`
7
votes
2
answers
15167
views
**
cat
without -n
**
user@linux:~$ cat /etc/sysctl.conf | head -4
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
user@linux:~$
There is -n
option in cat
command to display the line number of the file.
user@linux:~$ cat -n /etc/sysctl.conf | head -4
1 #
2 # /etc/sysctl.conf - Configuration file for setting system variables
3 # See /etc/sysctl.d/ for additional system variables.
4 # See sysctl.conf (5) for information.
user@linux:~$
user@linux:~$ cat -n /etc/sysctl.conf | tail -4
74 # Debian kernels have both set to 1 (restricted)
75 # See https://www.kernel.org/doc/Documentation/sysctl/fs.txt
76 #fs.protected_hardlinks=0
77 #fs.protected_symlinks=0
user@linux:~$
What about head
and tail
command? Is there any option to view the line number in head
and tail
without using cat -n
and pipe the output to head
or tail
?
I've tried head -n
and tail -n
but no line number displayed on the output.
user@linux:~$ head -n4 /etc/sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
user@linux:~$
user@linux:~$ tail -n4 /etc/sysctl.conf
# Debian kernels have both set to 1 (restricted)
# See https://www.kernel.org/doc/Documentation/sysctl/fs.txt
#fs.protected_hardlinks=0
#fs.protected_symlinks=0
user@linux:~$
Asked by user264359
May 28, 2019, 05:04 PM
Last activity: Oct 20, 2022, 02:14 PM
Last activity: Oct 20, 2022, 02:14 PM