vi replace second matching pattern in every line - Help Please sorry for double posting

vi replace second matching pattern in every line - Help Please sorry for double posting

Post by BN » Wed, 05 Apr 2006 01:57:26



Greetings,

Can some body help  me to replace the second match of a string in every

line in vi
unix, AIX 5L

Sorry for posting under a different topic.  For some reason its going
under a different topic,  I apologize for this.

Moving a bunch of files from one dir to other

mv /u01/oradata/XXXX/file1  /u01/oradata/XXXX/file1
mv /u01/oradata/XXXX/file2  /u01/oradata/XXXX/file2
mv /u02/oradata/XXXXX/file1a /u02/oradata/XXXXX/file1a
mv /u09/oradata/XXXX/file2a /u09/oradata/XXXX/file2a

I want to replace the 2nd XXXX to YYYYY

Regards & Thanks
BN

 
 
 

vi replace second matching pattern in every line - Help Please sorry for double posting

Post by Xichen » Wed, 05 Apr 2006 02:32:11



> Greetings,

> Can some body help  me to replace the second match of a string in every

> line in vi
> unix, AIX 5L

> Sorry for posting under a different topic.  For some reason its going
> under a different topic,  I apologize for this.

> Moving a bunch of files from one dir to other

> mv /u01/oradata/XXXX/file1  /u01/oradata/XXXX/file1
> mv /u01/oradata/XXXX/file2  /u01/oradata/XXXX/file2
> mv /u02/oradata/XXXXX/file1a /u02/oradata/XXXXX/file1a
> mv /u09/oradata/XXXX/file2a /u09/oradata/XXXX/file2a

> I want to replace the 2nd XXXX to YYYYY

in VIM:

%s/XXXX\(\/[^/]*\)$/YYYY\1/g

or with sed:

sed 's/XXXX/YYYY/2' myfile.txt

Xicheng

- Show quoted text -

Quote:> Regards & Thanks
> BN


 
 
 

1. How to replace a whole line (matching a pattern) in a text filke with SED ?

Assume I have a text file blah.dat. In that file there can be a line (or multiple lines)
among other lines containing the text fragment pattern "version" (without quotes).
Other characters can appear in these lines as well.

Now I want to replace ALL lines in this file with the text line "vers. release"
(without quotes). All other lines should remain untouched.
Order of lines should remain as well.

Example blah.dat:

kikik ikik ik kik kik  
hello version endofline
rtrtrtrtrtrtrt trtrtr

afterwards:

kikik ikik ik kik kik  
vers. release
rtrtrtrtrtrtrt trtrtr

I guess that this can be done most comfortable with the sed.
How do I do that ?

Thx
Matt

2. User Login Notification

3. vi: deleting lines based on pattern match

4. Multiple Consoles

5. Matching a pattern in a file and inserting variable string above the line matched?

6. How, in sh, to write a file onto tape-drive?

7. Vi multi-line pattern/replace question

8. Linux installation & IDE port

9. Matching Line After Pattern (Pattern Occurs Multiple Times)

10. Pattern matching and extracting the data which matches the pattern

11. inserting lines before and after lines with matching pattern using sed?

12. Help with Laserjet 4l and aps (sorry for the double post)

13. sorry for the double post but i still need help