LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-04-2010, 12:42 PM   #1
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 210
Blog Entries: 2

Rep: Reputation: 25
Word Count on Kate?


Is there a way I can get KDE Advanced Text Editor (KATE) to do word counts on documents I'm editing?

Thanks!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-04-2010, 01:20 PM   #2
jasohl
Member
 
Registered: Oct 2006
Location: Seattle, Washington
Distribution: Gentoo, LinuxMint, Arch Linux
Posts: 99

Rep: Reputation: 18
Doesn't look like it provides the option by default. But might be a plugin or script that supports it. There are some discussions on it if your Google it.
 
Old 08-04-2010, 02:21 PM   #3
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 210
Blog Entries: 2

Original Poster
Rep: Reputation: 25
I did google it. I didn't find anything. Posting to LQ was the last resort...
 
Old 08-04-2010, 02:26 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,497

Rep: Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883Reputation: 883
http://dissociatedpress.net/2006/04/...count-in-kate/
 
Old 08-04-2010, 02:34 PM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,149

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
You can save the file, select "Focus Terminal" to open a terminal window in a tab with it CWD set to where you save the document, and then run wc on the saved document.
 
Old 08-04-2010, 02:50 PM   #6
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 210
Blog Entries: 2

Original Poster
Rep: Reputation: 25
I read that one. I put the script in, rebooted Kate, and it did not work. I've been trying to get that one to work for hours. I did it exactly as Murz said to do it, too.
 
Old 08-04-2010, 03:22 PM   #7
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 210
Blog Entries: 2

Original Poster
Rep: Reputation: 25
Heh. Okay, well I managed to rewrite the script to give KATE a working word count system. The problem with Murz's script was $msg was not being defined due to some mysterious bug.

So me went paleolithic on that script and me brute force it. Me spruce it up a little, too. Ooga booga.

Do everything Murz said, namely (just in case that web page disappears):

1. Go to Settings – Configure kate
2. In “plugins” enable “External tools”
3. Go to “External tools” tab
4. Click “New”
5. Label: Selection stat

6. Now write the script this way:

Code:
msgww=`echo -E %text |wc -w`;msgwl=`echo -E %text | wc -l`;msgwb=`echo -E %text |wc -c`;msgsw=`echo -E %selection | wc -w`;msgsl=`echo -E %selection|wc -l`;msgsb=`echo -E %selection|wc -c`;kdialog --title "File Statistics" --msgbox "Selection:\nWord Count: 	$msgsw \nLines: 		$msgsl\nBytes:		$msgsb\n\n\nWhole Document:\nWord Count:	$msgww\nLines:		$msgwl\nBytes:		$msgwb\n\n\n"
7. Executable: kdialog

8. Command line name: selection_stat

Go to Tools, external tools, select "selection stat".

This will work whether you selected some text or want statistics on the entire document.

It now looks almost exactly like what you'd see in Textpad.
 
2 members found this post helpful.
Old 08-04-2010, 04:56 PM   #8
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,149

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
O.K., I looked at the code suggested, cut it, and pasted it into Kate. It didn't work for me, either until I pasted it into the Kate terminal. When I did that, I noticed that the backquote, quote, and single-quote characters in the command line had be "converted" to the extended (typographically correct, of course) forms. They look correct in the Kate edit window, but you need to go through and overtype them with the standard keyboard characters. You also need to replace the "-message" by a "--msgbox" in the kdiaog command. (The single, long, dash should, of course, be a double-dash.)

When that's done, you'll get a nice pop-up with the wc outpit in it for whatever you've selected.

Here's what I have in the "Script" section:
Code:
if [ -n "%selection" ]
then 
 msg=`echo -E "%selection" |\
 wc -cmwl |\
 sed 's/\s*\([0-9]*\)\s*\([0-9]*\)\s*\([0-9]*\)\s*\([0-9]*\)/Bytes: \4\nCharacters: \3\nWords: \2\nLines: \1/'`
  kdialog --msgbox "$msg"
else
  msg="Please select the text for which you desire statistics."
  kdialog --error "$msg"
fi
 
2 members found this post helpful.
Old 08-05-2010, 10:10 AM   #9
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 210
Blog Entries: 2

Original Poster
Rep: Reputation: 25
Quote:
Originally Posted by PTrenholme View Post
O.K., I looked at the code suggested, cut it, and pasted it into Kate. It didn't work for me, either until I pasted it into the Kate terminal...
Awesome deal. I knew it wasn't just me. So how do we mark this thread as solved?
 
Old 08-05-2010, 10:11 AM   #10
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
If it's solved, check the "Thread Tools" drop-down right atop the 1st post.
 
1 members found this post helpful.
Old 10-02-2010, 08:28 AM   #11
begtognen
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Rep: Reputation: 0
Hmm. I followed the instructions, using PTrenholme's code in the Script section.

I was able to do everything required, but when I exited Kate and restarted, there were no options under External Tools, and no scripts listed under the External Tools menu.

Is this because I'm running Kate under Gnome, do you think? Or am I doing something wrong?

Thanks so much for any help/suggestions you might have.
 
Old 10-03-2010, 02:04 PM   #12
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,149

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Hum. Well, I tried replacing the kdialog call with a dialog call, and it still failed to work on a GNOME system. So, all I can think of is that kate is using a KDE-specific method of running an embedded script. (Since kate is part of the KDE development kit, having an embedded KDE dependency is, of course, neither surprising nor a bug.)

Does gedit support script extensions? If it does, perhaps the script, or its equivalent, could be used with it.
 
Old 10-05-2010, 06:49 AM   #13
begtognen
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Rep: Reputation: 0
Ptrenholme - Thanks so much for getting back to me. I checked, and it turns out that gedit supports wordcount natively. Hooray!
 
Old 12-11-2011, 03:12 AM   #14
Zelator
Member
 
Registered: Jul 2005
Location: Melbourne Australia
Distribution: Netrunner
Posts: 68

Rep: Reputation: 15
Thumbs up Solution works for Kate 3.5.3

Thanks Raveolution! I've just installed Mepis 11 and my old fix was no good. Someday the Kate developers may supply a wordcount, but until then I'll have to rely on heroes like you. Or learn to code it myself.
 
Old 05-12-2012, 05:58 PM   #15
quixote9
LQ Newbie
 
Registered: May 2005
Location: Los Angeles
Distribution: Debian7
Posts: 13

Rep: Reputation: 0
I know that this is an old thread, but word count in Kate is such a huge gap, and PTrenholme's script at comment #8 actually provides a solution. So I felt I had to point that out, because here it is, 2012, and I searched for hours before stumbling on this. I'm using kde 4.7 running under LinuxMintDebian squeeze, with update4 applied.

Step by step: Sessions > Configure Kate. Under Application > Plugins, I ticked the box for "External Tools". Hit "Apply". That causes an "External Tools" entry to appear as a choice under Application. Select Application > External Tools, select the "New" button. Give the script any label that means something to you, copy and paste PTrenholme's script into the script box, under Executable enter "kdialog" (without the quotes), mime types can be left blank, Save can be None, and command is whatever you want to call this command. For instance "wcount".

Now, if you go to Tools > External Tools one of the choices will be wcount (or whatever you called it). If you use it often, you can go to Sessions > Configure Shortcuts and give it a keyboard shortcut.

(Oh, and hint to the Kate devs: INCLUDE THIS AS STANDARD WITH KATE )
 
  


Reply

Tags
count, editor, kate, text, word


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help in word count command grunge_1 Linux - General 4 03-20-2009 04:01 AM
variable length string using GD (word wrap, carriage return, word/character count)? frieza Programming 1 02-14-2009 05:21 PM
Word count with grep DiagonalArg Linux - Software 3 02-13-2006 12:46 PM
word count pantera Programming 2 08-31-2004 07:23 AM
word count in a line pantera Programming 4 08-25-2004 01:14 PM


All times are GMT -5. The time now is 07:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration