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

pcdls.ronin pcdls.ronin at gmail.com
Sat May 29 08:06:13 CDT 2010


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