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.)
.



Relevant Pages

  • Re: Starting kwrite: Parameter to show end of file?
    ... implemented as a wrapper script so that you can ... still invoke KWrite with its default behavior for other occasions... ... text without newline characters - and assign that value # to a second ... paragraph in the file will help us position the cursor on # the last ...
    (comp.os.linux.setup)
  • Re: Starting kwrite: Parameter to show end of file?
    ... implemented as a wrapper script so that you can ... still invoke KWrite with its default behavior for other occasions... ... # line of text without newline characters - and assign that value ... # longest paragraph in the file will help us position the cursor on ...
    (comp.os.linux.setup)
  • Re: "Ambiguous redirect" message
    ... asking for a way to have KWrite - an editor that ships with KDE - ... KWrite itself does not have any commandline options that support ... I have in the meantime perfected the script so that it properly exits ...
    (comp.unix.shell)
  • Re: "Ambiguous redirect" message
    ... appending text to the file right as it opens in the editor without ... KWrite itself does not have any commandline options that support this, ... I have in the meantime perfected the script so that it properly exits ... The two pertaining lines of code that give me these warnings are the ...
    (comp.unix.shell)
  • "Ambiguous redirect" message
    ... appending text to the file right as it opens in the editor without ... KWrite itself does not have any commandline options that support this, ... I have in the meantime perfected the script so that it properly exits ...
    (comp.unix.shell)