Sed is a powerful command akin to the find and replace feature in most text editors. Find out what sed is and how you can use it to improve your efficiency.
Like Geeks recently published an interesting series on writing Bash shell scripts:
Today we are going to talk about bash script or shell scripting actually, they are called shell scripts in general but we are going to call them bash scripts because we are going to use bash among the other Linux shells. There are zsh, tcsh , ksh and other shells, you can review the basic Linux commands before starting on bash script programming.
In the previous post, we talked about how to write a bash script. And we’ve seen how bash scripting is awesome. In this post, we continue to look at structured commands that control the flow of your shell scripts. You’ll see how you can perform repeating processes; this post demonstrates for loop, while in bash scripts
Today we will know how to retrieve input from the user and deal with that input so our script becomes more interactive.
On the previous post we’ve talked about parameters and options in detail and today we will talk about something is very important in shell scripting which is input & output & redirection.
On the last post, we’ve talked about input and output and redirection in bash scripting. Now you start building some Linux bash scripts, you may wonder how to run and control them on your Linux system. The only way we’ve run scripts is directly from the command line interface in real-time mode. This isn’t the only way to run Linux bash scripts in Linux.
If you get tired writing the same blocks of code over and over in your bash script. It would be nice to just write the block of code once and refer to that block of code anywhere in your bash script without having to rewrite it.
The bash shell provides a feature allowing you to do just that called Functions.
Bash functions are blocks of script code that you assign a name to and reuse anywhere in your code. Anytime you need to use that block of code in your script, you simply use the function name you assigned it.
We are going to talk about how to create your own bash functions and how to use them in other shell scripts.
On the previous post we’ve talked about bash functions and how to use it from the command line and we’ve seen some other cool stuff I recommend you to review it, Today we will talk about a very useful tool for string manipulation called sed, sed Linux command is one of the most common tools that people use to work with text files like log files, configuration files, and other text files. If you perform any type of data manipulation in your bash scripts, you want to become familiar with the sed and gawk tools in this post we are going to focus on sed Linux command and see its ability to manipulate text which is very important step in our bash scripting journey
On the previous post we’ve talked about sed Linux command and we’ve seen many examples of using it in text processing and how it is good in this, nobody can deny that sed is very handy tool but it has some limitations, sometimes you need a more advanced tool for manipulating data, one that provides a more programming-like environment giving you more control to modify data in a file more robust. This is where awk command comes in.
The awk command or GNU awk specifically because there are many extensions for awk out there takes stream editing one step further than the sed editor by providing a programming language instead of just editor commands.
In order to successfully working with the Linux sed editor and the awk command in your shell scripts you has to understand regular expressions or in short regex and to be accurate in our case it is bash regex, since there are many engines for regex you can use and we here in this regex tutorial will use the shell regex and see the bash power in working with regex.
First, we need to understand what regex is then we will dive deep into using it
Source: Regex tutorial for Linux
In the last post, we’ve talked about regex and we see how to use them in sed and awk for text processing and we discussed before Linux sed command and awk command. During the series, we write small shell scripts but we didn’t mix things up, I think we should take a small step and write a shell script that can be some useful.
The main reason for learning to write a shell script is to be able to create your own Linux utilities. Understanding how to write useful and practical scripts is important.
However, sometimes it helps to do something fun to learn a concept or skill. The scripts in this post they can be lots of fun! And they help empower your script writing concepts.
In the previous post we’ve talked about writing practical shell scripts and we’ve seen how it is easy to write a shell script and we’ve used most of our knowledge we’ve discussed on the previous posts, today we are going to talk about a tool that does magic to our shell scripts,that tool is expect command or expect programming language. Expect command or expect programming language is a language that talks with your interactive programs or scripts that require user interaction for input. Expect works by expecting input, and upon receiving the expected input, the Expect script will send the response without any user interaction, just like magic.
Introduction to using sed on the command line with regular expressions. Learn how to perform search and replace (substitution), printing, writing, reversing, and more!
How to use sed, a special editor for modifying files automatically. If you want to write a program to make changes in a file, sed is the tool to use.
There are a few programs that are the real workhorse in the UNIX toolbox. These programs are simple to use for simple applications, yet have a rich set of commands for performing complex actions. Don’t let the complex potential of a program keep you from making use of the simpler aspects. I’ll start with the simple concepts and introduce the advanced topics later on.
Full article here:
Sed – An Introduction and Tutorial (Grymoire)
Sed is a stream editor in UNIX like operating system which is used for filtering and transforming text. Sed is derived originally from the basic line editor ‘ed’, an editor you will find on every unix system but one that is rarely used because of its difficult user interface.
Full article here:
10 Sed (Stream Editor) Command Examples (NextStep4it)
A Linux Foundation Certified System Administrator (LFCS) has the expertise to do basic to intermediate system administration from the command-line for systems running Linux. Linux Foundation Certified System Administrators are knowledgeable in the operational support of Linux systems and services. They are responsible for first line troubleshooting and analysis, and choose when to raise issues to engineering teams.
The series will be titled Preparation for the LFCS (Linux Foundation Certified Sysadmin) Parts 1 through 10 and cover the following topics for Ubuntu, CentOS, and openSUSE:
Part 1: How to use GNU ‘sed’ Command to Create, Edit, and Manipulate files in Linux
Note: This article also touches on the use of several other commands used for processing text streams in Linux, such as uniq, sort, grep, tr, and cut.
Full article here:
LFCS: How to use GNU ‘sed’ Command to Create, Edit, and Manipulate files in Linux – Part 1 (Tecmint)
We must confess that we are not as fond of the Linux command line as some Linux users — we’ll take a good GUI, and a mouse over a keyboard any time we can. But for those that love working at the Linux command prompt (and that probably don’t make nearly as many typos as we do), we thought you might appreciate this series from the catonmat blog:
- Top Ten One-Liners from CommandLineFu Explained
- The Next Ten One-Liners from CommandLineFu Explained
- Another Ten One-Liners from CommandLineFu Explained
- Yet Another Ten One-Liners from CommandLineFu Explained
Or perhaps you’d prefer this series:
- Bash One-Liners Explained, Part I: Working with files
- Bash One-Liners Explained, Part II: Working with strings
- Bash One-Liners Explained, Part III: All about redirections
- Bash One-Liners Explained, Part IV: Working with history
- Bash One-Liners Explained, Part V: Navigating around
Or maybe you’d like to see one-liners covering Awk, Sed, or Perl:
- Famous Awk One-Liners Explained, Part I: File Spacing, Numbering and Calculations
- Famous Awk One-Liners Explained, Part II: Text Conversion and Substitution
- Famous Awk One-Liners Explained, Part III: Selective Printing and Deleting of Certain Lines
- Update on Famous Awk One-Liners Explained: String and Array Creation
- Famous Perl One-Liners Explained, Part I: File Spacing
- Famous Perl One-Liners Explained, Part II: Line Numbering
- Famous Perl One-Liners Explained, Part III: Calculations
- Famous Perl One-Liners Explained, Part IV: String and Array Creation
- Famous Perl One-Liners Explained, Part V: Text conversion and substitution
- Famous Perl One-Liners Explained, Part VI: Selective printing and deleting of lines
- Famous Perl One-Liners Explained, Part VII: Handy Regular Expressions
- Announcing perl1line.txt – Collection of Handy Perl Scripts
- Famous Sed One-Liners Explained, Part I: File Spacing, Numbering and Text Conversion and Substitution
- Famous Sed One-Liners Explained, Part II: Selective Printing of Certain Lines
- Famous Sed One-Liners Explained, Part III: Selective Deletion of Certain Lines and Special Applications
Author Peteris Krumins used these articles as the starting points for his e-books. In addition to the e-books listed there, it appears that he has authored this paperback edition that can be purchased from Amazon (this is an affiliate link, so if you buy it from here we’ll get a small commission):