1603206000
Play with text in Linux: Linux is a widely-used open-source operating system that provides a large number of text processing tools. In our everyday work, we need to search text, extract parts of the text, modify the text, and sort text. Linux shell has a number of useful tools that help us do various text processing tasks. In this blog, we are going to learn some most important text processing tools.
Here are the some most important test procession tool that we will discuss in this blog
GREP is a multi-purpose file search tool that uses Regular Expressions. The grep stands for “global regular expression print,” processes text line by line, and prints any lines which match a specified pattern. The grep command is used for searching the text from the file according to the regular expression. By default, grep displays the matching lines. Grep is considered to be one of the most useful commands on Linux and Unix-like operating systems. grep is a powerful file pattern searcher in Linux.
Syntax:
grep [options] pattern [files]
Most important Options:
-c: Count the number of lines that match a pattern.
-h: Display the matched lines, but do not display the filenames.
-i: Ignore case for matching.
-l: Displays list of a filenames only.
-n: Display the matched lines with line numbers.
-v: Prints all the lines that do not match the pattern.
-e exp: Specifies expression with this option. Can use multiple times.
-f file: Takes patterns from a file.
-E: Treats pattern as an extended regular expression (ERE).
-w: Match whole word.
-o : Print only the matched parts of a matching line.
Consider the below file as an input:
$cat > grepExample.txt
GREP is a multi-purpose file search tool that uses Regular Expressions.
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
1\. Case insensitive search
$ grep -i "GRep" grepExample.txt
output:
GREP is a multi-purpose file search tool that uses Regular Expressions.
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
2\. Displaying the count of the number of matches
$ grep -c "grep" grepExample.txt
output: 2
3\. Search the whole words in a file
$ grep -w "grep" grepExample.txt
output:
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
4\. Displaying only the matched pattern
$ grep -o "grep" grepExample.txt
output:
grep
grep
#devops #linux #awk #cut #grep #sed #shellscript
1603206000
Play with text in Linux: Linux is a widely-used open-source operating system that provides a large number of text processing tools. In our everyday work, we need to search text, extract parts of the text, modify the text, and sort text. Linux shell has a number of useful tools that help us do various text processing tasks. In this blog, we are going to learn some most important text processing tools.
Here are the some most important test procession tool that we will discuss in this blog
GREP is a multi-purpose file search tool that uses Regular Expressions. The grep stands for “global regular expression print,” processes text line by line, and prints any lines which match a specified pattern. The grep command is used for searching the text from the file according to the regular expression. By default, grep displays the matching lines. Grep is considered to be one of the most useful commands on Linux and Unix-like operating systems. grep is a powerful file pattern searcher in Linux.
Syntax:
grep [options] pattern [files]
Most important Options:
-c: Count the number of lines that match a pattern.
-h: Display the matched lines, but do not display the filenames.
-i: Ignore case for matching.
-l: Displays list of a filenames only.
-n: Display the matched lines with line numbers.
-v: Prints all the lines that do not match the pattern.
-e exp: Specifies expression with this option. Can use multiple times.
-f file: Takes patterns from a file.
-E: Treats pattern as an extended regular expression (ERE).
-w: Match whole word.
-o : Print only the matched parts of a matching line.
Consider the below file as an input:
$cat > grepExample.txt
GREP is a multi-purpose file search tool that uses Regular Expressions.
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
1\. Case insensitive search
$ grep -i "GRep" grepExample.txt
output:
GREP is a multi-purpose file search tool that uses Regular Expressions.
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
2\. Displaying the count of the number of matches
$ grep -c "grep" grepExample.txt
output: 2
3\. Search the whole words in a file
$ grep -w "grep" grepExample.txt
output:
The grep command is used for searching the text from the file according to the regular expression.
grep is a powerful file pattern searcher in Linux.
4\. Displaying only the matched pattern
$ grep -o "grep" grepExample.txt
output:
grep
grep
#devops #linux #awk #cut #grep #sed #shellscript
1650870267
In the previous chapters you've learnt how to select individual elements on a web page. But there are many occasions where you need to access a child, parent or ancestor element. See the JavaScript DOM nodes chapter to understand the logical relationships between the nodes in a DOM tree.
DOM node provides several properties and methods that allow you to navigate or traverse through the tree structure of the DOM and make changes very easily. In the following section we will learn how to navigate up, down, and sideways in the DOM tree using JavaScript.
You can use the firstChild
and lastChild
properties of the DOM node to access the first and last direct child node of a node, respectively. If the node doesn't have any child element, it returns null
.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
console.log(main.firstChild.nodeName); // Prints: #text
var hint = document.getElementById("hint");
console.log(hint.firstChild.nodeName); // Prints: SPAN
</script>
Note: The
nodeName
is a read-only property that returns the name of the current node as a string. For example, it returns the tag name for element node,#text
for text node,#comment
for comment node,#document
for document node, and so on.
If you notice the above example, the nodeName
of the first-child node of the main DIV element returns #text instead of H1. Because, whitespace such as spaces, tabs, newlines, etc. are valid characters and they form #text nodes and become a part of the DOM tree. Therefore, since the <div>
tag contains a newline before the <h1>
tag, so it will create a #text node.
To avoid the issue with firstChild
and lastChild
returning #text or #comment nodes, you could alternatively use the firstElementChild
and lastElementChild
properties to return only the first and last element node, respectively. But, it will not work in IE 9 and earlier.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
alert(main.firstElementChild.nodeName); // Outputs: H1
main.firstElementChild.style.color = "red";
var hint = document.getElementById("hint");
alert(hint.firstElementChild.nodeName); // Outputs: SPAN
hint.firstElementChild.style.color = "blue";
</script>
Similarly, you can use the childNodes
property to access all child nodes of a given element, where the first child node is assigned index 0. Here's an example:
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
// First check that the element has child nodes
if(main.hasChildNodes()) {
var nodes = main.childNodes;
// Loop through node list and display node name
for(var i = 0; i < nodes.length; i++) {
alert(nodes[i].nodeName);
}
}
</script>
The childNodes
returns all child nodes, including non-element nodes like text and comment nodes. To get a collection of only elements, use children
property instead.
<div id="main">
<h1 id="title">My Heading</h1>
<p id="hint"><span>This is some text.</span></p>
</div>
<script>
var main = document.getElementById("main");
// First check that the element has child nodes
if(main.hasChildNodes()) {
var nodes = main.children;
// Loop through node list and display node name
for(var i = 0; i < nodes.length; i++) {
alert(nodes[i].nodeName);
}
}
</script>
1594368382
Looking to develop real-time applications?
Hire Dedicated Linux Developer from HourlyDeveloper.io, we have dedicated developers who have vast experience in developing applications for Linux and UNIX operating systems and have in-depth knowledge of their processes, kernel tools, internal architectures, and development packages.
Consult with experts:- https://bit.ly/2ZQ5ySP
#hire linux dedicated developer #linux developer #linux development company #linux development services #linux development #linux developer
1597289640
This guide takes a tour of some of the best command-line tools that are used for searching matching strings or patterns in text files. These tools are usually used alongside regular expressions – shortened as REGEX – which are unique strings for describing a search pattern.
Without much further ado, let’s dive in.
Coming in the first place is the grep utility tool – is an acronym for Global Regular Expression Print, is a powerful command-line tool that comes in handy when searching for a specific string or a pattern in a file.
Grep ships with modern Linux distributions by default and gives you the flexibility to return various search results. With grep, you can perform a vast array of functioning such as:
The syntax for using the grep command is quite simple:
$ grep pattern FILE
For example, to search for the string ‘Linux‘ in a file, say, hello.txt while ignoring case sensitivity, run the command:
$ grep -i Linux hello.txt
Search For String in a File
To get more options that you can use with grep, simply read our article that examples more advanced grep command examples.
Sed – short for Stream Editor – is another useful command-line tool for manipulation text in a text file. Sed searches, filters and replaces strings in a given file in a non-interactive manner.
By default, sed command prints the output to STDOUT (Standard Out), implying that the result of the execution is printed on the terminal instead of being saved in a file.
Sed command is invoked as follows:
$ sed -OPTIONS command [ file to be edited ]
For example, to replace all instances of ‘Unix‘ with ‘Linux‘, invoke the command:
$ sed 's/Unix/Linux' hello.txt
Replace String in a File
If you want to redirect output instead of printing it on the terminal, use the redirection sign ( > )
as shown.
$ sed 's/Unix/Linux' hello.txt > output.txt
Redirect Output to File
The output of the command is saved to the output.txt file instead of being printed on the screen.
To check out more options that can be used, once again check out the man pages.
$ man sed
Ack is a fast and portable command-line tool written in Perl. Ack is considered a friendly replacement for grep utility and outputs results in a visually appealing manner.
Ack command searches the file or directory for the lines that contain the match for the search criteria. It then highlights the matching string in the lines.
Ack has the capacity to distinguish files based on their file extensions, and to a certain extent, the content in the files.
Ack command syntax:
$ ack [options] PATTERN [FILE...]
$ ack -f [options] [DIRECTORY...]
For example, to check for the search term Linux, run:
$ ack Linux hello.txt
Check a String in a File
The search tool is quite intelligent and If no file or directory is provided by the user, it searches the current directory and subdirectories for the search pattern.
In the example below, no file or directory has been provided, but ack has automatically detected the available file and searched for the matching pattern provided.
$ ack Linux
Search String in a Directory
To install ack on your system run the command:
$ sudo apt install ack-grep [On Debian/Ubuntu]
$ sudo dnf install ack-grep [On CentOS/RHEL]
#awk command #linux commands #sed command #commandline tools #linux tricks #linux
1603415915
This article is all about my journey on switching from Windows 10 to Linux Mint 20, how I got easily adapted to the Linux environment, and some resources that helped me to set up a perfect Desktop environment.
Ok, now I have decided to switch to Linux but here comes the first question. Which distro will satisfy my needs both in terms of GUI and other aspects? Linux is not something new to me since I have been working with RHEL based distros in my work for the past 4 years with the command-line.
I know RHEL based distros are good for enterprises but not for personalized desktop environments, at least that’s what I am thinking till now. So I started my research to find the distro that should be easy for me to use and at the same time should have good community support if in case I ran into some problem. Among many Linux distros, I drilled down my list to 4 flavors.
Related Article: The Best Linux Distributions for Beginners
Before deciding the Distro it is necessary you formulate the list of tools/programs or packages needed and check if the distro you choose provides all those features.
For me, I use Linux for two main purposes: one is for my professional development work, writing articles, and second for my personal use like Video editing and Movies. Most of the popular software are created to be compatible with Windows, macOS, and Linux like Sublime Text, VSCode, VLC Media Player, Firefox/Chromium browser. Other than these software, cloud-based services make our life easy Like Microsoft Office 365 or G Suite.
#linux distros #linux mint #linux distros #linux mint tips #linux