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.
This character matches the beginning of a string and lets you find all the strings with the same beginning.
$ grep ^B Bio.txt
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
This character lets you find any number of repetitions of a string
$ grep te* Rep.txt
This character lets you find strings matching a special symbol like a space “ “ or a new line “\n”
$ grep “\ “ RomCom.txt
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
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.
$ grep b[^i]g red.txt
You can also specify a range of characters to search for using the bracket. Here’s how.
$ grep b[a-e]g red.txt
Remember, the search range specification is case-sensitive.
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.
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.
Edit on Vim
Let us open a file to edit.
$ vim sample.txt
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?
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.
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
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.
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.
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