Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

replace text with a symbol in a file

 
SOLVED
Go to solution
Highlighted
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
Highlighted
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
Highlighted
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
Highlighted
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
Highlighted
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
Highlighted
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
Highlighted
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 ¶
Highlighted
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
Highlighted
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
Highlighted
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!!