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

pcdls.ronin pcdls.ronin at gmail.com
Sat May 29 10:29:48 CDT 2010


Don Davis wrote:
> 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
>
Your input text file looks like this?

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

If so, I can play with it later tonight.
pcdls


More information about the SATLUG mailing list