Operating System - HP-UX
1748232 Members
3347 Online
108759 Solutions
New Discussion юеВ

replace text with a symbol in a file

 
SOLVED
Go to solution
sahaj bahra
Frequent Advisor

replace text with a symbol in a file

A file is created though a tool which is supposed to be imported to windows and opened up in excel.
Now i see some text which needs to be converted to a symbol which will be used as a delimiter on excel.
Please help me out with a command or probably a script which will help do it.
Symbol i am looking for is ┬╢(paragraph).
Thanks..
10 REPLIES 10
sahaj bahra
Frequent Advisor

Re: replace text with a symbol in a file

The file is as below:

90966M-CM-^Q24936M-CM-^QDRM-CM-^Q M-CM-^QTemplateM-CM-^Q M-CM-^Q0M-CM-^Q M-CM-^Q M-CM-^Q M-CM-^Q M-CM-^Q0M-CM-^QCRM-CM-^Q2859
M-CM-^Q M-CM-^Q0M-CM-^Q M-CM-^Q0M-CM-^QSubeer ChatterjiM-CM-^Q109027M-CM-^QCR 2859-BI - Job Cost reports - Accept accounts

I need to replace M-CM-^Q with M-BM-6 in above file. This will let me see ├В┬╢ when i open the file with wordpad.
I used following command but no use:
sed 's/M-CM-^Q/M-BM-6/g' current.txt
Suraj K Sankari
Honored Contributor

Re: replace text with a symbol in a file

Hi,

Open this file into vi go to vi command prompt by pressing Ecs and then :

at : type below command and press return

:1,$s/M-CM-^Q//gp

Suraj
Suraj K Sankari
Honored Contributor

Re: replace text with a symbol in a file

hi again,

ohh forgot one thing to replace M-CM-^Q into M-BM-6 then you have to give below command
:1,$s/M-CM-^Q/M-BM-6/gp press 2 time return key

with sed

sed 's/M-CM-^Q/M-BM-6/g' outputfile

Suraj
Frank de Vries
Respected Contributor

Re: replace text with a symbol in a file

You were nearly there, just need to 'quote' the little carret ^ and it works ...

sed 's/M-CM-\^Q/M-BM-6/g' < test
Look before you leap
Suraj K Sankari
Honored Contributor

Re: replace text with a symbol in a file

Hi,

If ^Q character came by pressing Ctrl+V+Q then \ is required before ^ else its not required

Suraj
sahaj bahra
Frequent Advisor

Re: replace text with a symbol in a file

Thankq for all your input guys. But there is one catch. When i vi the file i get the below output:

90966├Г 24936├Г DR├Г ├Г Template├Г ├Г 0├Г ├Г ├Г ├Г ├Г 0├Г CR├Г 2859├Г ├Г 0├Г ├Г 0├Г Subeer Chatterji├Г 109027├Г CR 2859-BI - Job Cost rep
orts - Accept accounts without object account├Г After a change in the Capex Budget set up, we will use accounts without object
account.

I guess i will have to replace A character above but it needs to be done through sed only since i will use it in script later.
Attaching the file. see if you all can vi on it and see if the characters can be changed to ├В┬╢
Dennis Handly
Acclaimed Contributor
Solution

Re: replace text with a symbol in a file

>The file is as below:
90966M-CM-^Q24936M-CM-^QDRM-CM-^Q M-CM-^QTemplateM-CM-^Q

This more(1) output is useless. You need to use more -v. Or you need to use vi, or possibly vis.

>see if you all can vi on it and see if the characters can be changed to ├Г ├В┬╢

Yes, you can use vi. But I have no idea which char match your more(1) output.

Here is the "vis -x" output:
$ vis -x 326360.txt
90966\xc3\x9124936\xc3\x91DR\xc3\x91 \xc3\x91Template\xc3\x91 \xc3\x910\xc3\x91
\xc3\x91 \xc3\x91 \xc3\x91 \xc3\x910\xc3\x91CR\xc3\x912859\xc3\x91 \xc3\x910\xc3
\x91 \xc3\x910\xc3\x91Subeer

What needs to be changed?
M-CM-^Q is probably \xc3\x91
M-BM-6 is probably \xc2\xb6
Dennis Handly
Acclaimed Contributor

Re: replace text with a symbol in a file

Taking the above vis encoding you can create a sed script with inv(1):
echo 'sed "s/\xc3\x91/\xc2\xb6/g" 326360.txt' | inv >> sed_script.sh
sahaj bahra
Frequent Advisor

Re: replace text with a symbol in a file

Denis,
Thanks a lot. Your suggestion was to the point. I am able to run the script with the desired output now.

Thankq everyone!!