So I have a file where I want to move the last 3000 lines to another different file, and then create a new file from the original without the last 3000 lines.
I'm using a Mac and the command I used is as follows:
tail -n 3000 fer2017-testing-reduced.arff >> fer2017-training-reduced-3000-more-instances.arff; head -n -3000 fer2017-testing-reduced.arff > fer2017-testing-reduced-3000-less-instances.arff
However when I run this, I get the error:
head: illegal line count -- -3000
I'm not sure where I've gone wrong, or if this may be a mac issue?
Sed Command to Delete Lines – Based on Position in File In the following examples, the sed command removes the lines in file that are in a particular position in a file. Here N indicates Nth line in a file.
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.
To look at the last few lines of a file, use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file. Try using tail to look at the last five lines of your .
Linux Tail Command SyntaxTail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits.
Not all versions of head
support negative line counts.
The default installed on macOS doesn't.
If you have coreutils
installed (If you have Homebrew installed you can do this: brew install coreutils
) you should be able to use ghead -n -3000
.
If other tools are allowed, perhaps go for sed
sed -n '3000,${p}' file > filenew # print lines 3000 to end to new file
sed -i '3000,${d}' file # Use inplace edit to delete lines 3000 to end from orig.
The advantage here is that the $
auto matches the last line.
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