Shell Script with SED and Last Line Missing

I wrote a shell script that used SED to make context-specific changes along with copying files (among other things).  Out of the six scripts only one of them consistently experienced a problem – the last line was missing in all of the copies.

I wondered if there was some kind of dependency between the steps where something wasn’t getting properly written out, but that seemed odd for Unix.  I tried to do line by line comparisons to find the error in my shell scripts.  Finally, I came up with a different solution – simply add an additional blank line to the file to be copied.  After that, everything worked fine.

It wasn’t until I was studying SED in more detail yesterday that I realized that this was a necessary step.  SED seemed to ignore transforming or working with the last line of input that did not end with a newline.   I find this odd – if the last line of a file does not end with a newline, SED will ignore it?  There has to be more to the story than that.

Anyway, I am about halfway through my study with SED and will blog on that and then move on to AWK.

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