Linux: How to use the Advanced Text-Fu Command in Linux

Home /

Table of Contents

Advanced Text-Fu

Advanced Text-Fu is a set of tools and techniques used to manipulate and transform text in Linux. It includes various command line utilities and programming libraries that allow users to automate complex text operations. Some of the advanced features of Text-Fu include regular expressions, which allow users to search and replace text based on patterns, and the ability to integrate with other programming languages such as Python and Perl. Text-Fu can also be used to perform text analysis, such as counting word frequency and calculating readability scores. Other advanced techniques include using Text-Fu to extract data from structured text formats like XML and CSV files. With its powerful text manipulation capabilities, Text-Fu is an essential tool for anyone working with text data in Linux.

Regular Expressions (RegEx)

The regular expression, or RegEx, is a very effective technique for finding and matching data from a huge data set. They’re a set of characters that may be used to make pattern-based decisions. These characters are used with grep, sed, tr, vi, and other commands.

The syntax and usage of some of the fundamental RegEx characters are shown here.

Using ‘^’

This character matches the beginning of a string and lets you find all the strings with the same beginning.

$ grep ^B Bio.txt

HytxdI gZI6THV7 ClHGYjhhoZDyZtqXwLbEZ6SvX8 FHAPW 2B3RTKg99E5U Lh87VGX1p hpinvXpnHuwXOVmFmyVKoHnfx pon8pf1U8WGnEFAdE nACboEnYki3DbcKWqGOOC s5SKLAFamcgX0rzYxQr LttWVnUp2i4UO4cN6nr FvNnb - Linux: How to use the Advanced Text-Fu Command in Linux

Using ‘.’

This character lets you find a specific string even if you forgot certain characters of it. Just replace the missing characters with ‘.’

$ grep Be.gman Bio.txt

oWIU6JXwDtTYgPX1dMTWRje0qwskd00eKSgS PxkfudJm8m6HnNNrwsIa6l7acHV5RZ8 g9Ikc4EQr EgDBOY9YUwAO16cqzLpiBcrlQ8OVJprrFlBOUpbaubwN5cB k9FV6gV37RBRoZvn5VJmdGWW 52t qmDD EFBCUt8wH BT2XpGuARktwU - Linux: How to use the Advanced Text-Fu Command in Linux

Using ‘*’

This character lets you find any number of repetitions of a string

$ grep te* Rep.txt


hTxAllsgncfWOfgvQhdKvmTgTq84PXez7faikVOma41hk1L5daKbP7H6LMfUJC UKz1YHtOsqVjmWtNLKYY4zQpmRlcOK2sfOfWYGZruvUWg eQDQuU1DxGXXUOIAZqXO AjGZx1YX8TEcyt0BnZt9Q46KVN OSHU21FocfpgOibj40ShUbYvdnz - Linux: How to use the Advanced Text-Fu Command in Linux

Using ‘\’

This character lets you find strings matching a special symbol like a space “ “ or a new line “\n”

$ grep “\ “ RomCom.txt

Using ‘[]’

Using this ‘[]’ you can perform some complicated search operations fairly easily. Stating b[aio]g would make the system check for the characters within the bracket one by one and get the strings if it finds them. The example below will clarify it more.

$ grep b[aio]g red.txt

NT YHGCAnBXgIins6u4dc8UR5biAGCQ8d9fmrIyTt0OPcmOBdhxMb 8 3Um6duz5IUh9pYNRxj69 WOgQCyP6 945q8KPL0go9T19dKT2qpi2AGRwlQQUzANMoZ18QMBvleGIwxUgf2EcYo3b1NISaOTytab9IC mB5SQcd3fBdC9SIV6gx MjfM - Linux: How to use the Advanced Text-Fu Command in Linux

If you use a character with ‘^’ alongside, all the strings will be shown except for the one having that specific character. See the example below.

N8hd5mEPwK1vMM3SEUznG80tv0xZg03GPrdr5s1mrn2hGwehyOuXKOmDMMI ZXepMUZ YMr4p8mGWitJ M42lCJiaObR BC5gpuLFciq984yOGymTVB5uO 0snzzYyeOq7 - Linux: How to use the Advanced Text-Fu Command in Linux

$ grep b[^i]g red.txt


IfddbY73drLl5aq xFw7XKGV2drVQ DnxFwV6VPPINy42ZywtwVLTkbTZWCuV3dvunvLsFO jp6wLFS6ySxZsu6HMZ1MQOCmNddPROIY5YvKQRvA v r7 qMxOpPryInFBrTH81Tm1Ad Wv73Greq 7W1dx2 iu2FrUazDZzDJkG0mC2zqiwGRMr - Linux: How to use the Advanced Text-Fu Command in Linux

You can also specify a range of characters to search for using the bracket. Here’s how.

$ grep b[a-e]g red.txt


ghxYKclpHcLw0KbUmNM88BongaVSQ8Fe99jjLqUt guP4s4ztbeDj3oonRyGkGHtxSVMMGf533JOFXgCuakxTIZIvibs1uDxtzfMLLrLst1WSGnVtNXv1kODdp8x2cDOU22e fz8gDJKnd4spIjrKxzheTkrFKxTIWkao1RZTrHw9XnT8xW Zo1U - Linux: How to use the Advanced Text-Fu Command in Linux

Remember, the search range specification is case-sensitive.

Text Editors

Vim and emacs are generally always installed as default text editors in Linux systems. They are the most widely used text editors across a wide range of users. They provide word processing and coding services. In this part, we will analyze their advantages and disadvantages to assist you in selecting the ideal one for you. So please bear with me.

Vi Improved (Vim)

It is, as the name implies, an improved version of the vi text editor tool. It is incredibly light, making it easier to open and edit files. If you have vim installed on your machine, simply type the following command into your terminal to open it.

$ vim

8si0bN 3NRxQb6zw65TLgcSi8oHroRlh9uVtOvY8YUCSDLU7cfJ9q6DY30sKMcxqoPJ4bR3v eHGzRHVeYZPNGOfyVAm5WEPW gI8 TX 13a4Qde34zJfVB PbEYOUSJGQv eKOCJlQ9H RgAY07GzW0myL2gXZEZu5y3f7rsb8WAQW4uRP445Iw - Linux: How to use the Advanced Text-Fu Command in Linux

So, it happens that my system does not have vim by default. If this is also the case for you, perform the command listed below.

$ sudo apt install vim
$ sudo apt update

That’s all. You have successfully installed vim in your system. Now, run the ‘vim’ command again.


OVFVOqcdUfRqnA kN5iBh7tCy0s7DS8yh2VYgChVcN6 - Linux: How to use the Advanced Text-Fu Command in Linux

Edit on Vim

Let us open a file to edit. 

$ vim sample.txt


2Isu tRoJNVqBctxPomrZspikM Q6Ht6gURj5jChecnnoxZxXVPnulYzBThXsoJmSj05qxESXw R7s4S9t - Linux: How to use the Advanced Text-Fu Command in Linux

The contents of the sample.txt file may be seen using this command. You will then see that you are unable to make any changes to the file. To change anything, write hi, and an ‘INSERT’ indicator text will appear at the bottom. You may now modify any part of the file. I prefer to end the poem with another line. Are you familiar with this poem?

B7pDUCI3A3pP05YQmrr1CaE2gc jkVddmPA98yBLW bNqxpzRvvMkNwZ Lei7Mudiom CmQneN6c1SuV38DTWFjP3KojHwU2O79tJWGQrTwMeCgV8TjOVEAcV53p8D27krFzd Cd2oJx4UrjPtrUlGJWZiUxC1DNPj TJWvANqYwyBQbkUHLZaDd - Linux: How to use the Advanced Text-Fu Command in Linux

You must hit the ‘Esc’ key to exit the operation or any other operation in VIM. You may now perform another operation. The ‘o’ key will take you to a new line, and the ‘u’ key will allow you to reverse any modifications.


kyNXKyJTnX7aWxuDDmtIrVl1Q5GQ8ugWwIbq8 aF tQ Le j7I1T9EeZZFojIdCtg 7v3aqQ8bw9hXNZXXR9KQSnW315c8lBVYksCrX1yYVhElZSr8ZNQB2ctCIsXlwQ8v9EMWio7S - Linux: How to use the Advanced Text-Fu Command in Linux

Now that you have made some changes to the file, you want to save it. Type ‘:w’ to save the changes. Last, ‘:q’ is used for quitting from vim without saving changes. 

Navigation in Vim

You can not navigate anywhere in Vim using the mouse. For this, you have to run the following keys:

  • ‘j’ or down key for moving down one line
  • ‘k’  or up key for moving up one line
  •  ‘h’ or left key for moving one character left
  • ‘L’ or right key for moving one character right   

Emacs

For Linux and UNIX systems, Emacs is one of the most popular and flexible text editors. It’s a sophisticated text editor with a lot of features. It takes a bit longer to load than Vim and has a steeper learning curve, but if you want a strong, versatile editor, this is it.

To install emacs, you need to run the following command.

$ sudo apt install e3

Then, running the ‘emacs’ command opens the emacs window. 


- Linux: How to use the Advanced Text-Fu Command in Linux

It asks for a file name. After you enter the file name, this will take you to the editor. Now, you can add or make changes as you wish. Let’s see how it looks.

pBeNmIQRuz0zXDdjDFmHfUfqVOxK5dV3OB76ZoUEdFgTlN1W OPeT3SAonn9XtUrykfvyl1QDynmPcWYjFV4t 8gTpvBq5mBPvi waCzF7Elhd5MmWiA0YTqrs22LynZ4A6YvJIJmQbsewBYs0PNu2io2vH51aKG9OP4WRxEX8 5L SZEGod3rGX - Linux: How to use the Advanced Text-Fu Command in Linux

To save the file that you make changes you need to run ‘ctrl-x and then ‘ctrl-s’. To exit from emacs, you need to run ‘ctrl-x’ followed by ‘ctrl-c’.

Navigation in Emacs

Like in Vim, you can not use the mouse to navigate through the file here. For this, you need to use the following commands.

  • Ctrl-f: move one character right
  • Ctrl-n: move to the next line
  • Ctrl-b: move one character left
  • Ctrl-p: move to the previous line
  • ctrl-e: move to the end of the line
  • Ctrl-a: move to the beginning of the line
Share The Tutorial With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Check Our Ebook for This Online Course

Advanced topics are covered in this ebook with many practical examples.

Other Recommended Article