Merging 2 lines together

I have a small problem, which due to my lack of knowledge, has left me unable to decipher some of the solutions that I looked at on these forums.

So below is a piece of text, which I ran via cat -vet, which comes from within a program file. I have many such programs to process and repeatable, hence why I am looking to sort it out once and for all :slight_smile:

DEFINE NEW GLOBAL SHARED VARIABLE http-newline AS char NO-UNDO$
    INITIAL "~^M~$
".$

The problem is as follows. I wish to be able to remove the CTRL-M from within the

<B>"~^M~</B>

and bring the following line onto the same line as the

~^"M~

. So in effect the

"~^M~

becomes

"~~"

There could be multiple instances within the same program/text.

At the moment I have used perl to find the ~^M~ to remove the CTRL-M, as below.

perl -pi -e 's/\~\r\~/~~/gi' ProgramText.p

I have searched for

~^M~

to reduce the chance of a false match. I appreciate that some of the switches may be unnecessary in the above Perl.

I need to append whatever is on the next line, which at the moment is "., just incase what is on the next line changes at some time in the future.

If necessary I can use the perl I have already to remove the CTRL-M, and sed to perform the append, using the

"~~"

as the search criteria for the sed. Just looking for some pointers.

$ sed '/\^M/ {s/\^M//g;N;s/\n//}' file
DEFINE NEW GLOBAL SHARED VARIABLE http-newline AS char NO-UNDO$
INITIAL "~~$".$
1 Like

Thanks RudiC, I will give that a go this afternoon. Thanks to Jim for properly displaying my post.

May I ask in the solution, how, what, where, since there seems a lot going on in a single line.

Seems like the

sed '/\^M/

is searching the ^M and then substitutes ^M .... and then I lose any understanding.

1 Like

Thank you, that makes more sense to me now, especially the relationship being the '/\^M/ and the rest of commands in the { }.