Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document?I.e. I just want to get everything but the first 2 lines of foo.txt to append to another document.
How to obtain inverse behavior for `tail` and `head`?
text processing;tail;head
You can use this to strip the first two lines:tail -n +3 foo.txtand this to strip the last two lines:head -n -2 foo.txt(assuming the file ends with \n for the latter)Just like for the standard usage of tail and head these operations are not destructive. Use >out.txt if you want to redirect the output to some new file:tail -n +3 foo.txt >out.txtIn the case out.txt already exists, it will overwrite this file. Use >>out.txt instead of >out.txt if you'd rather have the output appended to out.txt.