How VPS - How to use/setup VPS
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Fun in Linux Terminal – Play with Word and Character Counts

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
27
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Sample Output
  2. Sample Output
  3. Sample Output
  4. Sample Output
  5. Sample Output
  6. Sample Output
  7. Sample Output

Linux command line has a lot of fun around itself and many tedious task can be performed very easily yet with perfection. Playing with words and characters, their frequency in a text file, etc is what we are going to see in this article.

The only command that comes to our mind, for tweaking Linux command line to manipulate words and characters from a text file is wc command.

Fun in Linux Terminal – Play with Word and Character Counts

Fun with Word and Letter Counts in Shell

A ‘wc‘ command which stands for word count is capable of Printing Newline, word & byte counts from a text file.

To work with the small scripts to analyze text file, we must have a text file. To maintain uniformity, we are creating a text file with the output of man command, as described below.

$ man man > man.txt

The above command creates a text file ‘man.txt‘ with the content of ‘manual page‘ for ‘man‘ command.

We want to check the most common words, in the above created ‘Text File‘ by running the below script.

$ cat man.txt | tr ' '  '2' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | grep -v '[^a-z]' | sort | uniq -c | sort -rn | head
Sample Output
7557 
262 the 
163 to 
112 is 
112 a 
78 of 
78 manual 
76 and 
64 if 
63 be

The above one liner simple script shows, ten most frequently appearing words and their frequency of appearance, in the text file.

How about breaking down a word into individual using following command.

$ echo 'tecmint team' | fold -w1
Sample Output
t 
e 
c 
m 
i 
n 
t 
t 
e 
a 
m

Note: Here, ‘-w1’ is for width.

Now we will be breaking down every single word in a text file, sort the result and get the desired output with the frequency of ten most frequent characters.

$ fold -w1 < man.txt | sort | uniq -c | sort -rn | head
Sample Output
8579  
2413 e
1987 a
1875 t
1644 i
1553 n
1522 o
1514 s
1224 r
1021 l

How about getting most frequent characters in the text file with uppercase and lowercase differently along with their occurrence frequency.

$ fold -w1 < man.txt | sort | tr '[:lower:]' '[:upper:]' | uniq -c | sort -rn | head -20
Sample Output
11636  
2504 E 
2079 A 
2005 T 
1729 I 
1645 N 
1632 S 
1580 o
1269 R 
1055 L 
836 H 
791 P 
766 D 
753 C 
725 M 
690 U 
605 F 
504 G 
352 Y 
344 .

Check the above output, where punctuation mark is included. Lets strip out punctuation, with ‘tr‘ command. Here we go:

$ fold -w1 < man.txt | tr '[:lower:]' '[:upper:]' | sort | tr -d '[:punct:]' | uniq -c | sort -rn | head -20
Sample Output
  11636  
  2504 E 
  2079 A 
  2005 T 
  1729 I 
  1645 N 
  1632 S 
  1580 O 
  1550 
  1269 R 
  1055 L 
   836 H 
   791 P 
   766 D 
   753 C 
   725 M 
   690 U 
   605 F 
   504 G 
   352 Y

Now I have three text files, lets run the above one liner script to see the output.

$ cat *.txt | fold -w1 | tr '[:lower:]' '[:upper:]' | sort | tr -d '[:punct:]' | uniq -c | sort -rn | head -8
Sample Output
  11636  
   2504 E 
   2079 A 
   2005 T 
   1729 I 
   1645 N 
   1632 S 
   1580 O

Next we will be generating those infrequent letters that are at least ten letters long. Here is the simple script.

$ cat man.txt | tr '' '2' | tr '[:upper:]' '[:lower:]' | tr -d '[:punct:]' | tr -d '[0-9]' | sort | uniq -c | sort -n |  grep -E '..................' | head
Sample Output
1        ────────────────────────────────────────── 
1        a all 
1        abc             any or all arguments within   are optional 
1               able  see setlocale for precise details 
1        ab              options delimited by  cannot be used together 
1               achieved by using the less environment variable 
1              a child process returned a nonzero exit status 
1               act as if this option was supplied using the name as a filename 
1               activate local mode  format and display  local  manual  files 
1               acute accent

Note: The more and more dots in the above script till all the results are generated. We can use .{10} to get ten character matches.

These simple scripts, also make us know most frequent appearing words and characters in English.

That’s all for now. I’ll be here again with another interesting and off the beat topic worth knowing, which you people will love to read. Don’t forget to provide us with your valuable feedback in comment section, below.

Read Also: 20 Funny Commands of Linux

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
How VPS

How VPS

Related Posts

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Install Apache Tomcat 8 on CentOS 7
Linux

How to Install Apache Tomcat 8 on CentOS 7?

February 11, 2020
Install Arch Linux With Btrfs Snapshotting
Uncategorized

Install Arch Linux With Btrfs Snapshotting

February 13, 2020
Next Post

Understanding Shell Commands Easily Using “Explain Shell” Script in Linux

How To Install And Configure Advanced Poll For Use With Fastcgi On IIS 6

How To Install And Configure Advanced Poll For Use With Fastcgi On IIS 6

How To Prepare For Migration To Windows Server 2019

How To Prepare For Migration To Windows Server 2019

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

Using Finnix Rescue CD to Rescue, Repair, or Backup Your Linux System

3 years ago
Webmin Reviews

Webmin Reviews

3 years ago

How to Install BigTree CMS on a Fedora 26 LAMP VPS

3 years ago

Set Date and Time for Each Command You Execute in Bash History

4 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8 February 25, 2022
  • How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.