Sponsored Content
Top Forums Shell Programming and Scripting replacing text in a file, but... Post 302264984 by Angelseph on Friday 5th of December 2008 09:22:31 AM
Old 12-05-2008
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 for something else...
but before you think of sed's substitution 's///' or python's s.replace() method or similar ways, the resulting text should NOT be the same for every occurrence of "aaa", that is, I need the replacements to be unique (this does not happens with the above functions as all of the occurrences are replaced with the same text.

For example, for the first occurrence of "aaa" replace it with "aaa1", the second "aaa2" and so forth. I doesn't necessarily have to be sequential it just has to be unique.

Any input is appreciated,
Thank you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing strings with text from other file

Hi, Im trying to update some properties files with text from another file: file1 user=xyz file2 user= after script file2 user=xyz Im using this reading the $QUARTZURL,ETC... from quartz.properties: echo... (1 Reply)
Discussion started by: mc1392
1 Replies

2. 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

3. Shell Programming and Scripting

Replacing Block of lines in a text file

Dear All, Regards of the Day. I have a text file with some functions: Function1 { parameter 1 parameter 2 parameter 3 } end Function2 { parameter 1 parameter 2 parameter 3 } (1 Reply)
Discussion started by: ashisharora
1 Replies

4. Shell Programming and Scripting

replacing text with contents from another file

I'm trying to change the ramfs size in kernel .config automatically. I have a ramfs_size file generated with du -s cat ramfs_size 64512 I want to replace the linux .config's ramdisk size with the above value CONFIG_BLK_DEV_RAM_SIZE=73728 Right now I'm doing something dumb like: ... (3 Replies)
Discussion started by: amoeba
3 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. 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

7. Shell Programming and Scripting

Replacing in huge text file

I have huge text files (~120 MB)x100 which equivalents to ~11GB of data. The files contain pure numbers, actually the value of "phi" to 10 billion digits!! I know its huge!! Here are the last few lines of a file 0952899155 3233967444 3344925499 0276061529 7261968933 9683989044 3317145063... (14 Replies)
Discussion started by: shantanuthatte
14 Replies

8. Programming

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... (2 Replies)
Discussion started by: agupta2
2 Replies

9. UNIX for Dummies Questions & Answers

Replacing all cells that have a specific value in a text file

I have a space delimited text file where I want to replace all cells that are 0 with NA. However I cannot simply use 'sed/0/NA/g' because there are other 0's in the text file that are part of numbers. Example input: 896.933464285715 0 874.691732142857 866.404660714286 Output:... (1 Reply)
Discussion started by: evelibertine
1 Replies

10. Programming

Replacing a word of a text file, in C++ fstream

How to replace a word in text file using c++ fstream. Is there a way, without creating any temporary file. Could you please share pseudo code ??? (1 Reply)
Discussion started by: techmonk
1 Replies
DwtCSTextReplace(3Dwt)													    DwtCSTextReplace(3Dwt)

Name
       DwtCSTextReplace - Replaces a portion of the current text in the compound-string text widget or inserts some new text into the current text
       of the compound-string text widget.

Syntax
       void DwtCSTextReplace(widget, from_pos, to_pos, value)
	    Widget widget;
	    int from_pos, to_pos;
	    DwtCompString value;

Arguments
       widget	 Specifies the ID of the compound-string text widget.

       from_pos  Specifies the first character position of the compound-string text being replaced.

       to_pos	 Specifies the last character position of the compound-string text being replaced.

       value	 Specifies the text to replace part of the current text in the compound-string text widget.

Description
       The DwtCSTextReplace function replaces part of the text in the compound-string text widget.  Within  the  widget,  positions  are  numbered
       starting  at  0 and increasing sequentially.  For example, to replace the second and third characters in the text, from_pos should be 1 and
       to_pos should be 3.  To insert text after the fourth character, from_pos and to_pos should both be 4.

See Also
       DwtCSText(3Dwt), DwtCSTextCreate(3Dwt), DwtCSTextSetString(3Dwt),  DwtCSTextGetEditable(3Dwt),  DwtCSTextSetEditable(3Dwt),  DwtCS-
       TextGetMaxLength(3Dwt), DwtCSTextSetMaxLength(3Dwt), DwtCSTextSetSelection(3Dwt), DwtCSTextGetSelection(3Dwt)
       Guide to the XUI Toolkit: C Language Binding
       Guide to the XUI Toolkit Intrinsics: C Language Binding

															    DwtCSTextReplace(3Dwt)
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy