Useful sed command example

sed is a stream editor that you can invoke on the command line. I needed it to do a global search and replace on a json file that Pluma choked on.

This example does a global substitute of 0072bb and replaces it with 0055A4 on a file named sheet1.json and writes the output to the new file named sheet2.json

sed 's/0072bb/0055A4/g' sheet1.json > sheet2.json

The s in the string is for substitute and the g is for global. The first named file is the input. The > symbol is used to redirect the output which sed normally writes to stdout (screen monitor) to the named file (sheet2.json).

3 Likes

Thanks for reminding us of the usefulness of Linux through the application of command line operations. Back in 1997, the O'Reilly line of books released an entire tome on sed and awk, titled (not surprisingly) "Sed & Awk." It's still in print here.

3 Likes

It is rare that any of my scripts don't have one, if not both, of those commands, mostly awk in my case! :slight_smile:

I can't answer that, as I'm the only Linux guy in a sea of Windows and Mac users. :slight_smile:

Many years ago when storage was expensive and RAM was rare, I managed a system that required moving Oracle data files from one system to another. A simple ftp would choke the network, so I used a process of "chunking" the files and moving them via a named pipe. The files would all have a numeric suffix appended to them and I needed to rename each. There could be lots of them! I don't still have the code I wrote, but I used sed and awk to gather a list of the files, modify the names in the process and then rename them as output.

To do that manually would have taken a lot of time that was better spent drinking coffee and reading InfoWorld.