Need help for replacing a string in a text file at runtime !


 
Thread Tools Search this Thread
Top Forums Programming Need help for replacing a string in a text file at runtime !
# 1  
Old 11-08-2011
Need help for replacing a string in a text file at runtime !

Hi All,

I am facing an issue... I need to replace some string in a text file while the same file is read by some other user at the same time. The other user is using it in the Read only mode. So I can't create a temporary file and write the content first and then write it back into the original file.

Please let me know if anyone have any sample code (C/C++) or any info related to this issue.

Thanks in advance!!!
# 2  
Old 11-08-2011
Quote:
Originally Posted by agupta2
Hi All,

I am facing an issue... I need to replace some string in a text file while the same file is read by some other user at the same time. The other user is using it in the Read only mode. So I can't create a temporary file and write the content first and then write it back into the original file.

Please let me know if anyone have any sample code (C/C++) or any info related to this issue.

Thanks in advance!!!
Look at the mmap function as it does what you are trying to do here...one process maps a file as shared into its address space while the other process accesses it in read only mode.
# 3  
Old 11-08-2011
This only works if the read-only user has it mapped in, not when they get it via read().

The consequences of changing data in the middle of a file while in use are unknown and potentially bad. They may just be ignored if the data's already been checked once. Catch it at the right moment and it may only see partial changes. Even with the right timing, the program may react badly to having the floor changed from underneath it. Doing this to a shell script for example will probably cause it to bomb out with syntax errors.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing text in between the string

Here is just a few variations that follow the same principle. We need to update the path to all images (only images) <IMG src="/3251_8832613.jpg"> <IMG src="https://www.unix.com/images/1303_4703925.jpg"> <IMG src="\\SERVER\DATA\Image\1948_4703925.jpg"> <img... (12 Replies)
Discussion started by: 2by4
12 Replies

2. Shell Programming and Scripting

Replacing string values from a File

I want to replace string values from a file to a file For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is. For example: From file (File1) cluster.name=secondaryCluster To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies

3. UNIX for Dummies Questions & Answers

replacing a string with another string in a txt file

Dear all, I have a file like below. I want to replace all the '.' in the 3rd column with 'NA'. I don't know how to do that. Anyone has an iead? Thanks a lot! 8 70003200 21.6206 9 70005700 17.5064 10 70002200 . 11 70005100 19.1001 17 70008000 16.1970 32 70012400 26.3465 33... (9 Replies)
Discussion started by: forevertl
9 Replies

4. UNIX for Dummies Questions & Answers

Replacing a column in a text file

Say I had a text file that contained four columns, like the following: Mack Christopher:237 Avondale Blvd:970-791-6419:S Ben Macdonor:30 Dragon Rd:647-288-6395:B I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no... (6 Replies)
Discussion started by: Sotau
6 Replies

5. UNIX for Dummies Questions & Answers

Help parsing and replacing text with file name

Hi everyone, I'm having trouble figuring this one out. I have ~100 *.fa files with multiple lines of fasta sequences like this: file1.fa >xyzsequence atcatgcacac...... ataccgagagg..... atataccagag..... >abcsequence atgagatatat..... acacacggd..... atcgaacac.... agttccagat.... The... (2 Replies)
Discussion started by: mycoguy
2 Replies

6. Shell Programming and Scripting

Replacing a character string in a file

Hi there, I have a paramater file that looks like this :- IRL|07122005|27389|VTIEpay|email address|5|200 When my program finishes I want to replace the seventh field. the existing code is like this cat <<-EOF | ed -s $PARFILE 1,$ g/^$ICO/s/$prvdate/$TODAY/ 1,$... (13 Replies)
Discussion started by: rjsha1
13 Replies

7. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

8. Shell Programming and Scripting

Replacing Text in Text file

Hi Guys, I am needing some help writing a shell script to replace the following in a text file /opt/was/apps/was61 with some other path eg /usr/blan/blah/blah. I know that i can do it using sed or perl but just having difficulty writing the escape characters for it All Help... (3 Replies)
Discussion started by: cgilchrist
3 Replies

9. Shell Programming and Scripting

replacing string in an XML file

Hi all, I need to replace string in XML file..XML file like <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> <dependency> ... (2 Replies)
Discussion started by: subin_bala
2 Replies
Login or Register to Ask a Question