Comparing sed stream output in linux

Sed is very very powerful, which is a good thing to be aware of.
I was looking to compare the output of a sed command to the original file before I wanted to execute the sed command directly on the file and came across this handy trick.

It works by using temporary named pipes inside the diff command.

Contents of file:

One
Two
Three
Four
Five

If I just want to remove the line which begins with “Four”, I can check my sed command like this:

joris@beanie ~
$ diff <(sed '/Four/d' numbers.txt) numbers.txt
3a4
> Four

Awesome possum, now I know my sed command won’t destroy anything.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s