script to replace a character with '(Apostrophe)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to replace a character with '(Apostrophe)
# 1  
Old 07-31-2009
script to replace a character with '(Apostrophe)

Hi Friends,

I need a sed or awk based script to replace a character(alphabet) with ' (Apostrophe). I tried to use the following two commands

1) sed -e 's/a/'/' filename
2) awk '{sub("a","'",$1);print}' filename

but both got failed.
Any help on this.

Thanks in advance..
# 2  
Old 07-31-2009
Quote:
Originally Posted by ks_reddy
Hi Friends,

I need a sed or awk based script to replace a character(alphabet) with ' (Apostrophe). I tried to use the following two commands

1) sed -e 's/a/'/' filename
2) awk '{sub("a","'",$1);print}' filename

but both got failed.
Any help on this.

Thanks in advance..
Code:
/home/chris>cat test.out
testing a  script
/home/chris>sed -i "s:a:\':g" test.out
/home/chris>cat test.out
testing ' script

# 3  
Old 07-31-2009
You're close, you can do it with:

sed -e "s/a/'/" filename (note the quote types.)
# 4  
Old 07-31-2009
Another way with tr :
Code:
tr a "'" <infile

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to replace nth character with comma

I have a requirement as below. In one of my column, I have data which may or may not be separted with coma always. Now I need to validate the length of these text within the coma (if available) and if the length is more than 30 characters, I need to insert a coma either at 30 characters if its... (3 Replies)
Discussion started by: aramacha
3 Replies

2. Shell Programming and Scripting

Bash script to replace a character with another

Hi. I'm a complete noob when it comes to scripting. I have approximately 2000 files scattered throughout different locations that I need to rename. The current files have a character, "." , that needs to be replaced with an underscore. I have no clue which route to go about correcting this.... (4 Replies)
Discussion started by: Nvizn
4 Replies

3. Shell Programming and Scripting

Replace apostrophe with backslash apostrophe

I'm coding using BASH and have a requirement to replace apostrophes with backslash apostrophes. For example below: I am here 'in my room' ok Would be changed to: I am here /'in my room/' ok The original text is coming from a field in a MySql database and is being used by another process that... (5 Replies)
Discussion started by: dbjock
5 Replies

4. Shell Programming and Scripting

Replace multiple occurances of same character with a single character.

Hi all, Greetings, I have the following scenario, The contents of main file are like : Unix|||||forum|||||||||||||||is||||||the||best so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it And i need the output in the following form: Unix=forum=is=the=best so=be=on=it ... (3 Replies)
Discussion started by: dipanchandra
3 Replies

5. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

6. Shell Programming and Scripting

script command to replace character

Hi, i have log like this : Actually i want to change the time stamp, and the rule is like this : and My script is like this : I know the script will loop and loop again after 07:00 like this: Can somebody help me ?? Thanks in advance.. (5 Replies)
Discussion started by: justbow
5 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. UNIX for Dummies Questions & Answers

How to replace special chars like " ' " (Apostrophe)

I'm goin to drive crazy soon, if i can not do this. I have a text file (570kb) and i have to replace the apostrophe " ' " and minus "-" with space " ". i have done it for minus: sed 's/-/ /g' aaa.txt >zzz.txt this replaced minus with space. but i can not use the same command for ' . ... (4 Replies)
Discussion started by: onculo
4 Replies

9. UNIX for Dummies Questions & Answers

How to Replace,Sort,and Append Character one script

Hi all i am very new to shell scripting,hope u guys can help i need to replace,sort and append character for the file that look like this: 1007032811010001000100000001X700026930409 1007032811010001000200000002X700026930409 1007032711020001000300000003X700026930409... (2 Replies)
Discussion started by: ashikin_8119
2 Replies

10. Shell Programming and Scripting

Escaping apostrophe using shell script

Hi, I am using the KSH shell. I am facing a problem of escaping apostrophe('), that is occuring in a variable. I used the following command, but in vain item=`echo $item|sed 's/&apos;/\'/g'` this code replaces the occurance of &apos; in an xml file to apostrophe(') symbol. The output of... (2 Replies)
Discussion started by: mradul_kaushik
2 Replies
Login or Register to Ask a Question