replace text


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replace text
# 1  
Old 07-01-2011
replace text

Hello

I'm trying to replace in a text file the chain by 107,192,196,207 107.207 but I can not

I tried the following

cat translator_swift.properties.in_modif | sed 's/107\,207/107,192,196,207/g' > translator_swift.properties.in_modif

Can you help me? thanks
# 2  
Old 07-01-2011
I am confused. What is the target string to replace, and what is the replacement.

No need for cat, put file on end of sed command line before shell stdout redirect.

Must make new file, sed is not vi.
# 3  
Old 07-01-2011
Sorry

the text that I want change is

107.207
by
107,192,196,207

this change I have to do in several files and want to do it automatically, searching and replacing.

With "cat" works, look

**DEV** properties $ grep EXT_HOST_ADDR sandbox.cfg
EXT_HOST_ADDR=22.34.43.14
**DEV** properties $ cat sandbox.cfg | sed 's/EXT_HOST_ADDR=22.34.43.14/EXT_HOST_ADDR=adgmm101/g' > sandbox.cfg
**DEV** properties $ grep EXT_HOST_ADDR sandbox.cfg
EXT_HOST_ADDR=adgmm101
# 4  
Old 07-01-2011
Are you trying to change every
107.207
to
107,192,196,207
??

For example:
original myfile.txt
Code:
val=106.209
val=107.207
val=109,153,202,199

to myfile.txt
Code:
val=106.209
val=107,192,196,207
val=109,153,202,199

# 5  
Old 07-01-2011
107,207 by 107,192,196,207
, are comma
# 6  
Old 07-01-2011
[QUOTE=nonanov;302535750]
Quote:
With "cat" works, look

**DEV** properties $ grep EXT_HOST_ADDR sandbox.cfg
EXT_HOST_ADDR=22.34.43.14
**DEV** properties $ cat sandbox.cfg | sed 's/EXT_HOST_ADDR=22.34.43.14/EXT_HOST_ADDR=adgmm101/g' > sandbox.cfg
This is very very dangerous. The >sandbox.cfg overwrites sandbox.cfg entirely, and doesn't wait for sed to finish reading before it does so! If sed doesn't read in the entire file before the shell truncates it, much or all of it could be lost! That's probably what's happening when you don't use cat. With the cat, it takes a fraction of a second longer, giving sed a chance to read at least some of it (but NOT guaranteed to be all of it).

If you have Linux, you can use sed -i '/expression/' filename to safely edit the file "in place". It creates a temp file, then replaces filename with the temp file.

If you don't, you have to use a temp file yourself:

Code:
sed '/expression/' < input >/tmp/$$
# 'cat' is better than 'mv' since it won't alter input's ownership or permissions
cat /tmp/$$ >input
rm /tmp/$$


Last edited by Corona688; 07-01-2011 at 04:27 PM..
# 7  
Old 07-01-2011
I hate to think we are some lingual warp with by and to. My third line was the most important,
Code:
sed 's/old/new/g' file1 > file2

. comma is not meta but dot is.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exact Text Replace

I am currently working with a bash script to change some names around in 3 files. I am attempting to do this with sed but I haven't been able to get it so it won't replace partial matches. Below is an example of the files I am trying to edit. My main goal is to replace foo with test, but I... (4 Replies)
Discussion started by: Takau
4 Replies

2. UNIX for Advanced & Expert Users

Search and replace text

HI I have property files having content QA_server_name=10.232.54.7 QA_port_number=18000 DEV_server_name=10.235.60.73 DEV_port_number=18000 and a .jason file having content like this { "server":"localhost" "port":"17000" ------ } I will get the parameter... (1 Reply)
Discussion started by: mdtausifsh
1 Replies

3. UNIX for Dummies Questions & Answers

Replace text

Hi, I have 50 shells in a particular directory. In each shell, we have a variable MAIL_SUCCESS=abc@xyz.com,def@xyz.com,emi@xyz.com The variable could be different. Now my requirement is I've to replace abc with def in all the shells present. I have been able to get the command for that: ... (3 Replies)
Discussion started by: donisback
3 Replies

4. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

5. Shell Programming and Scripting

replace text

What command can I use to replace the last part of a text string with different text. Example: I want to replace the text NAME in the following string with the text NEW_NAME abc~diff~other~something~NAME The number of ~ can change. (4 Replies)
Discussion started by: jody325
4 Replies

6. Shell Programming and Scripting

How to replace text in a file with text entered

I am trying to write a shell script that will allow the typing of a value, then using that value to replace data in a text file. I suspect I need sed. The format of the file is: Variable1:Value1 Variable2:Value2 The interaction would be something like: Shell Prompt: "Please enter the... (9 Replies)
Discussion started by: cleanden
9 Replies

7. Shell Programming and Scripting

find text but replace a text beside it

I have an html file that looks like this (this is just a part of the html file): <td colspan="3" rowspan="1" style="text-align: center; background-color: rgb(<!-- IDENTIFIER1 -->51, 255, 51);"><small><!-- IDENTIFIER2 -->UP</small></td> This is to automatically update the status of the... (4 Replies)
Discussion started by: The One
4 Replies

8. UNIX for Advanced & Expert Users

Replace the text between two lines with different text

I have a file which contains the following data. Parameters "CParameters" BEGIN DSSUBRECORD Name "TgtDB" Prompt "TgtDB" Default "edwdev" ParamType "0" ParamLength "0" ParamScale "0" END DSSUBRECORD MetaBag... (6 Replies)
Discussion started by: ukatru
6 Replies

9. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

10. UNIX for Dummies Questions & Answers

Replace Text

I have i/p file with following text --> 456 StreetA Rd (702) 456-7890 123 StreetB Rd 345-5678 789 StreetC Rd 123-8765 356 StreetD Rd (702) 657-3456 I want o/p file like below --> 456 StreetA Rd (702) 456-7890 123 StreetB Rd (702) 345-5678 789 StreetC Rd (702)... (2 Replies)
Discussion started by: deep.singh
2 Replies
Login or Register to Ask a Question