

It is not a text editor, but it helps to manipulate and filter text.

Sed (stands for stream editor) is a very powerful and handy utility in Linux that allows us to perform basic text manipulations on the input streams. To open the Terminal, use the Ctrl+Alt+T keyboard shortcut. We will use the default Ubuntu Terminal application for running the commands. You can also run the same commands on other Linux distributions. We will be running the commands on Ubuntu 20.04 Focal Fossa. Remove both leading and trailing whitespaces.In this article, we will be discussing the use of sed for removing whitespaces from the data. In some other articles, we have discussed the use of awk in removing the whitespaces. To remove whitespaces from your document, you can use various tools such as awk, sed, cut, and tr. The tab is a whitespace character which contains multiple spaces. egrep -v '\S' example.txt Regex Ignore Space or Whitespace Regex Tab. In this example, we will only print the lines that do not contain any space. It all becomes more challenging when you need to remove all those leading and trailing whitespaces from a document containing thousands of lines. If we want to skip the space or whitespace in the given text we will use -v before the \S. The same is the case with double spaces which are also sometimes difficult to spot. However, it is not easy to spot the trailing whitespaces. If we talk about leading whitespaces, they are relatively easy to spot as they are at the start of the text. For simplifying the command-line output.Following are some scenarios where you might need to remove whitespaces: It helps to store only the required data and get rid of unnecessary leading and trailing spaces. Removing whitespaces in documents is an essential formatting step that is required to improve the overall layout of a text and to ensure data is clean and tidy.
