Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Activate the "Text Filter" plugin, select the text, and start the filter (Tools->Filter Text, or Ctrl+/). In the pop-up box, check the "Copy" box and enter the "wc -w" command in the text box. You word count will be the top entry in your clipboard, which you can paste anywhere you want, or just look at in your copy stack.
Indeed, the Tools->Filter Text does work, but if, like me, you need to check the word count frequently, it is a bit cumbersome. I have Konsole open with a wc command in it that I can alt/tab to and from very quickly. It's either that or Libre Office until someone fixes Kate. I'd love to do it myself but the learning curve would be over the horizon.
A general solution: word count for any text selection using Klipper
O.K., here's a "work around" that works for me:
Create this script, say kwc, in a directory in your search path. (I have a ~/bin directory I use for such things.)
Code:
if [ -n "$1" ]
then
msg="$(echo "$1" | wc -cmwl | gawk '{printf("%s line%s\n%s word%s\n%s character%s\n",$1,($1>1)?"s":"",$2,($2>1)?"s":"",$3,($3>1)?"s":"")}')"
kdialog --msgbox "${msg}"
else
msg="Please select the text for which you desire statistics."
kdialog --error "${msg}"
fi
Make the code executable (e.g., chmod +x ~/bin/kwc)
Install the clipboard tool (I use Klipper since I run under KDE, but I think that GNOME has a similar tool.) Note: The following assumes klipper.
Right click on the clipboard in the task bar, and click the "Enable user actions" box.
Create a action, with no regular expression, containing kwc %s. (Use whatever your name choice you made, and any description you want. Be sure to pass the %s argument to the script -- that's the "current active clipboard contents.")
Open the Klipper "Configure Kilpper" item, and verify that the "Synchronize contents of the clipboard and the selection" is checked, and, optionally -- depending on how else you use you clipboard -- check the "Text selection only" box. (Note that you can also change your history size here.)
Close the Klipper configurarion window.
Go to kate or, actually, anywhere you can do a text selection, and select some text.
Right-click on the Klipper in the task bar, and click on the "Manually select a user action." item, and then select kwc (or whatever you called it) in the pop-up.
Last edited by PTrenholme; 05-19-2013 at 03:24 PM.
Reason: Minor typo
If you have the terminal activated, there is a simple solution to use wc in it:
* type wc<enter> in terminal, wc is waiting for input now
* select text you want to count
* tools - pipe to terminal
* press ctrl-d in terminal to end the input
Press "Edit -> Replace..." (you're not going to replace, but if you pressed "Find..." you could not see the "mode" section.
Be sure that "Mode: " is set to "Regular expression"
Write one of the following into "Find: " box to count:
characters: [^\0]
words: [^\s]
(including square brackets)
Finally, press "Find All". Its result count is what you need.
If you forget it, once used, you can retrieve them in the history of "Find: " box.
Unfortunately this not works. I tried with Kate 15.12.3 and 16.08.0 and they have same problem with search. It stops search after a quite small threshold (few thousand search occurrences) on a quite small data portion. The threshold is not constant and it can count different number on same conditions (text and search). You will not get any alert and just get wrong result. I test with file not stored on disk (just copy/paste few lines in editor window)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.