tail the last line of a file
Hi,
In my current unix server, if I need to tail the last line of a file, I need to type tail -0 <filename> as opposed to tail -1 <filename>. I'm wondering if it is because of the Linux kernel version. Do different shells have different behavior, e.g. Korn Shell and Bash. Thanks in advance. |
It's probably due to your version of tail. Does your tail not have the -n flag? That's generally what I use:
Code:
tail -n 1 <filename> |
Quote:
|
I'd imagine they'd all be 0 and it is most likely determined by command itself. The only difference would most likely be how lines are determined. Not to mention most programming counters start w/0, unless purposefully skipped.
|
What distro are you using and what is your version of tail?
Code:
tail --version |
Quote:
$tail --version Usage: tail [-f] [-c number|-n number|-m number|-b number|-k number] [file] Usage: tail [-r] [-n number] [file] Usage: tail [+|-[number]][l|b|c|k|m][f] [file] |
What system are you running this on?
|
Quote:
|
Quote:
|
Does that work ?
Code:
sed -n '$p' <filename> |
Quote:
|
The differences are mostly due to the source of the basic system utilities, rather than the shell* or the system.
I believe most of the traditional flavors of Unix provide their own home-spun implementations of the basic core utilities, while Linux distros pretty much all use the ones written by the gnu organization. While the command names and basic posix-defined functions should be the same across all *nixes, they can sometimes be quite different in their operating details and the exact mix of features they support. The gnu ones in particular have often been greatly expanded with additional features not available elsewhere (e.g. the -i in-file-editing option in sed). *Although there are syntax differences between bash and ksh, for example, each shell will generally work the same across all platforms, barring the occasional feature that isn't supported by some underlying system. Edit: Here are the manpage for aix and the gnu documentation, so you can compare their features. They don't appear to say anything about using 0 vs 1, however. http://publib.boulder.ibm.com/infoce...cmds5/tail.htm http://www.gnu.org/software/coreutil...nvocation.html |
Hmmmm interesting about head. If I think about it -- it probably uses Line 0 POS 0 = 0 Where as if fully reversed Line 0 POS EOF = 0. Which would make sense head vs tail.
|
Quote:
|
Ok - I see now - ty for explanation.
|
All times are GMT -5. The time now is 03:25 AM. |