Search and replace sed or tr

Hi folks,
I need to search and replace specific text in a file and replace it. I have a text file that does not have any newlines or carriage returns. All newlines have been removed. Here is what I need to do.

Find the exact string �DH� (quotes included) and replace it with \n�DH� (basically putting a newline in front of all occurances of �DH�)

I have tried using sed...
sed 's/\<"DH"\>/\"DH"/g' DHt.txt > DH2.txt
When I tried the sed example the output has nothing in it. I think this is because there are no newlines or carriage returns.

And tr command...
tr -s '["DH"]' '[\\012"DH"]' < DHu.txt > DHt.txt
This replaces anything with DH in it and the newline is not added, it adds \012. It needs to to find only �DH�

Now I'm pretty new this type Unix commands so my syntax could easliy be wrong .

Thank all in advance,
Joaquin

maybe it is hard to work only used sed or tr
but you cant do it both used sed and tr
for example :you can used sed to add a special char before "DH" then used tr to replace the special char by \n

Hello Bridgeje,

One possibility is to open the file in vi and do the following:

:%s/"DH"/^M"DH"/g

for ^M you should type ctrl v, crtl enter

I tired the insert character and earch and replace it with \n, but that speacial character could be in the file and I cannot replace it.

I also tried vi and then typing
:%s/"DH"/^M"DH"/g
But I must have done something wrong, when I type in the line it says "what" Is there a way to type it in the command line?

Thanlks for the help eveyone,
Joaquin

maybe you can try this (i had ran the code in bash shell )
cat yourfile|sed s'/\(\"DH\"\)/\
> \1/'g

The problem with these suggestions is that they are intended to be used on text files. The operative definition of text file is a collection of lines. The OP does not have a file that is a collection of lines nor would he have one if he succeeds in doing what he wants.

If I really had to solve this this problem, I would write a special purpose C program. I'm not a perl expert, but I strongly suspect that perl could also handle this problem.

Any perl programmers out there? :wink:

Try using a sed script, containing...

s/DH/\
DH/g

Use it like this...

sed -f scriptfile file1 > file2