Re: [SLUG] Conversion question

From: Chuck Hast (wchast@gmail.com)
Date: Thu Jan 18 2007 - 12:09:47 EST


On 1/18/07, Daniel Jarboe <daniel.jarboe@gmail.com> wrote:
>
> > 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 :)

Agree, I will just put it in a little file so when the command parser for the
switch interface calls something, it is calling a file with a name that does not
match TR and inside that file is the execution of the tr command that will fix
it, but at the same time I am going to play with sed, this is a good place to
learn this sort of thing, and I am sure that there are places where I will need
to use sed to do that sort of thing because tr has it's limits too.

This is fun, and I am learning more and more about how to do neat tricks
with Linux, basic to most of you but high level stuff to me....

-- 
Chuck Hast  -- KP4DJT --
To paraphrase my flight instructor;
"the only dumb question is the one you DID NOT ask resulting in my going
out and having to identify your bits and pieces in the midst of torn
and twisted metal."
-----------------------------------------------------------------------
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:46 EDT