Re: [SLUG] Conversion question

From: Daniel Jarboe (daniel.jarboe@gmail.com)
Date: Thu Jan 18 2007 - 11:28:31 EST


> Can not figure out why sed is not getting rid of the LF... It sticks the
> CR in there but for some reason I can not get it to remove the LF.

The reason why is because sed is line-oriented. In order to accomplish what
you want with sed, you need to work with multi-line blocks of text by adding
the next line to the pattern space buffer before match/replacing, and you
end up with more complicated sed scripts. Fortunately, you are not the first
to have this problem, and resources like the sed FAQ provide additional
information.

The sed FAQ recommends:
sed ':a;N;$!ba;s/\n//g' filename

The basic idea is here:
sed 'N;s/\n//g'

get the next line into the pattern space buffer "N"
replace \n with an empty string "s/\n//g"

To that base, they add the creation of label a ":a"
and the command to branch back to label a for every line except the last
"$!ba"

Frankly, I find tr -d '\n' easier to recall and harder to mess up :)
~ Daniel

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:40:40 EDT