I want to output all lines of a file, but skip last 4, on Terminal.
As per UNIX man page following could be a solution.
head -n -4 main.m
MAN Page:
-n, --lines=[-]N print the first N lines instead of the first 10; with the lead- ing '-', print all but the last N lines of each file
I read man page here. http://unixhelp.ed.ac.uk/CGI/man-cgi?head
But on MAC OSx I get following error.
head: illegal line count -- -4
What else can be done to achieve this goal?
To quickly turn head pointer on or off using the Accessibility Shortcuts panel, press Option-Command-F5 (or if your Mac or Magic Keyboard has Touch ID, quickly press Touch ID three times).
Use the tail command to write the file specified by the File parameter to standard output beginning at a specified point. This displays the last 10 lines of the accounts file.
Hold option ( alt on some keyboards) and press the arrow keys left or right to move by word. Simple as that. Also ctrl e will take you to the end of the line and ctrl a will take you to the start.
Use logrotate to do this automatically for you. there would be some exception case might come like no free space available to store log archive file (logrotate) in the server. For that kind of situation we have to keep only latest logs and remove other old log entries.
Use awk
for example:
$ cat file
line 1
line 2
line 3
line 4
line 5
line 6
$ awk 'n>=4 { print a[n%4] } { a[n%4]=$0; n=n+1 }' file
line 1
line 2
$
It can be simplified to awk 'n>=4 { print a[n%4] } { a[n++%4]=$0 }'
but I'm not sure if all awk implementations support it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With