Text scanning/processing and Link creation in Linux

Text scanning/processing and Link creation in Linux

Photo by Max Chen on Unsplash

Today we will talk about all the cool concepts of how we can scan and process files/texts and use it in our day to day usage !! Let's practice and get working on it, together!!

GREP:

(Global Regular Expression Print) This filter searches a file for a particular pattern of characters , and displays all the lines that contains that pattern.

Options:

-I : for case insensitive text search

-r : to search all files recursively

-c : to display to line count of line that has the desired string

Suppose we have to send all files which has "Janahvi" word in it to a new file.

AWK:

This is used to do pattern scanning and processing. When using awk , you are able to select data – one or more pieces of individual text – based on a pattern you provide.

Suppose we need to find all files with keyword "INFO" with only column first and second for data from arguments.log file.

Find:

Find command is used to search and locate the list of files and directories based on conditions we specify for the files that match the arguments. These arguments can be based on various factors like finding by group name, user names, permission sets, file type/size, data etc. Let's take some examples:

SED:

SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution).The sed command modifies lines from the specified File parameter according to an edit script and writes them to standard output. The sed command includes many features for selecting lines to be modified and making changes only to the selected lines.

Taking an example, we have a file NewText.txt with some text written in it, if we want to replace "Linux" to "unix"; here 's' is the argument given for substitute.

Head/Tail:

As the name suggests; head displays the top lines of the file and tail display the bottom lines of the file. (head and tail without any arguments will give 10 lines from top and bottom respectively)

Let's take an example for copying top 5 and bottom 3 files from users' file to a new file called NewFile.txt

Link in linux is a pointer to a file. Creating links is a kind of shortcuts to access a file.There are two types of links :

  1. Soft Link or Symbolic links

  2. Hard Links

These links behave differently when the source of the link (what is being linked to) is moved or removed. Symbolic or soft links are not updated (they merely contain a string which is the path name of its target); hard links always refer to the source, even if moved or removed.

For example, if we have a file a.txt. If we create a hard link to the file and then delete the file, we can still access the file using hard link. But if we create a soft link of the file and then delete the file, we can’t access the file through soft link and soft link becomes dangling. Basically hard link increases reference count of a location while soft links work as a shortcut.

Stay tuned folks!!