[SATLUG] how to use tr to remove newlines after '--'

Don Davis dondavis at reglue.org
Sat May 29 13:25:24 CDT 2010


Thank you, I tried it out with no luck.
Depending on how well the new lines copy - this is the text in file with :
1 --$
--$
--$
NOT $
SCORED --$
--$
NO $
$

1 --
--
--
NOT
SCORED --
--
NO




pcdls.ronin wrote:
> Don Davis wrote:
>> I have a file and I'm trying to remove newline characters after lines 
>> that end with '--'
>>
>> using:
>> tr '\-\-\n' '\-\- '
>> removes _ALL_ new lines not only the ones after '--'
>> and sed -e 's/--$/foo/g' |tr 'foo\n' ' '
>> does as well.
>>
>> Suggestions?
> Tried the following as a command that is supposed to take a string and 
> replace it with another string.  I used your string --\n (the string 
> that you want to replace) and replaced it with just the --.  I used the 
> echo functions to see that it removed the \n and essentially 
> concatenated some of the strings together in an expected fashion.
> 
> (echo --; echo -z; echo -x; echo --; echo -*) | sed '/--$/ {
> N
> s:--\n:--:
> }'
> 
> For a file, I guess you could do the following:
> 
> sed  '/--$/ {
> N
> s:--\n:--:g
> }' foobar.txt > test.txt
> 
> With output going to test.txt.  It isn't tested.  Let us know how it 
> works out.
> 
> pcdls



More information about the SATLUG mailing list