Replace word with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace word with sed
# 1  
Old 01-04-2011
Replace word with sed

Hi there.!

I'm trying to make a script that corrects wrong spelling. I want to use sed to replace wrong word with the correct one, but this must be made in a while loop that reads the wrong word from file (with read line) and the correct one from another file. I can't find a way to run sed like this.

This is the part of my code:

Code:
while read line
      do
        echo $line": mispelled"
        echo "Write the correct word:"
        read x <> /dev/tty
        echo $x > file
        sed 's/$line/$cat file/'g $1 > newfile
      done< errors

I think that $line and $cat file is wrong but I don't have any idea and I can't also save them in variables.

I would appreciate your help if possible

Thanks,
Spiridoula

Last edited by spiii; 01-04-2011 at 09:33 PM..
# 2  
Old 01-04-2011
Code:
sed "s/$line/$cat file/"g $1

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 01-04-2011
Quote:
Originally Posted by rdcwayx
Code:
sed "s/$line/$cat file/"g $1

Thanks.! But nothing changed.! The word is not replaced...Ouf.!
# 4  
Old 01-04-2011
No need to echo $x out to a file just use it in your sed script directly:

Code:
sed "s/$line/$x/g" $1 > newfile

What if you have teh => the what about words like tehran and gatehouse?
Have you considered how different case letters should be handled?

Last edited by Chubler_XL; 01-04-2011 at 10:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing a particular word with another word in all the xml's under a particular directory with sed

Hi Folks, Could you please advise what will be the SED command to replace a word in all xml's under a particular directory for example let say I rite now at the following below location $ cd /ter/rap/config now under config directory there will be lots of xml file , now my objective is to... (1 Reply)
Discussion started by: punpun66
1 Replies

2. Shell Programming and Scripting

Using sed to replace a word at specific location

I'm try to change a the prohibit to aix for the lines starting with ssh and emagent and rest should be the same. Can anyone please suggest me how to do that using a shell script or sed passwd account required /usr/lib/security/pam_prohibit passwd session required ... (13 Replies)
Discussion started by: pjeedu2247
13 Replies

3. Shell Programming and Scripting

Replace a word using sed

Hi, I have the following line in file1 export NAME="NEW_NAME" I'm writing a shell script which reads the NEW_NAME from the user and replace in the file. I have used the following command for that read Name_replace sed -i 's/NEW_NAME/$Name_replace/' file1 but it is not... (2 Replies)
Discussion started by: Ananthdoss
2 Replies

4. Shell Programming and Scripting

sed command to replace a word with new line and /

Hi, I have been trying to replace the key word "SQL> spool off " with "/ show errors" with out double quotes in all the files in a directory. above show erros should be displayed next line Could you please help me how to do that. I have tried something like this... (3 Replies)
Discussion started by: pointers
3 Replies

5. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

6. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

7. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

8. Shell Programming and Scripting

Sed - need to replace a word by another in 82 files.

HI everyone ;) I looking for help to use sed. I have 82 files. In each file I need to replace a word by another. All files are on the same directory.all files are texte files. I need to keep the same file name for all file that will be modified. Here is an exemple : file name :... (7 Replies)
Discussion started by: Aswex
7 Replies

9. Shell Programming and Scripting

sed search and replace word assistance...

Hi, I am trying to write a shell script designed to take input line by line by line from a file with a word on each line for editing with sed. Example file: 1.ejverything 2.bllown 3.maikling 4.manegement 5.existjing 6.systems My design currently takes input from the user, and... (2 Replies)
Discussion started by: mkfitzwilliams
2 Replies

10. Shell Programming and Scripting

replace word with using "sed" not work...

Hi, I have a xml text file with the following data, I would like replace F0</Number> to F</Number> only. i used sed to replace, but it not work!! anyone can help? <Number>11 20 03 22 23 21 91 00 F0</Number> <Number>12 20 03 20 99 21 91 20 F0</Number> <Number>10 21 03 21 78 21 92 27... (28 Replies)
Discussion started by: happyv
28 Replies
Login or Register to Ask a Question