Re: Starting kwrite: Parameter to show end of file?



On Tue, 17 Aug 2010 12:05:13 -0400, Maurice Batey <maurice@xxxxxxxxxxxxxxxxx> wrote:

On Mon, 16 Aug 2010 21:51:13 -0400, David W. Hodgins wrote:
kwrite --line $(wc -l filename.txt)

Thank, David (and GangGreene).
It almost works; puts the cursor position *above* the last line of
the file!

Confirmed. Turns out wc -l returns the number of newline characters
in the file, rather then the number of lines, so the count it returns
is one less than what an editor like kwrite will show. I was
surprised by this, but if you look at a text file in hex, the
last line.

Parsing the output of wc, to separate the number of lines and
the file name, and then adding one to the number of lines, before
invoking kwrite, would be easy in a script, but due to nesting
issues, very difficult to do on one line.

#!/bin/bash
newlinesplusfilename=$(wc -l "$1")
newlines="${newlinesplusfilename%% *}" # Strip space and after.
lines=$(($newlines+1))
kwrite --line "$lines" "$1"

In testing, what kwrite displays, depends on if the last line
ends with a new line or not. Strange. Using kate instead
of kwrite in the script, does show the last line, in my
limited testing.

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
.