How do we remove specific text from each line in a text file in Linux? In this post we cover using Sed to remove text from a line in Linux.
We previously covered in this post adding text to a line in Linux. In this post we will be specifically talking about the opposite. Using Sed to remove text from a line in linux is fairly straight forward. To remove specific characters or portion of text from a line in Linux we can use command line bash tool sed. The tool sed is used to perform basic text transformations, more info on sed can be found here. In the below example we want to specifically remove ‘BARRY\’ from a line everything within the square brackets [text to remove] is removed, so we use:
cat users | grep BARRY | cut -d" " -f 2 | sed 's/[BARRY\]//g'
Hopefully you will find this useful!