The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 09-29-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,527
Quote:
Originally Posted by muxman
That deletes the match. What I'm after is to negate it. Instead of replacing the match, replace EVERYTHING ELSE and leave the match alone.
Alternative in Python:
Code:
#!/usr/bin/python
all = open("file1.txt").read()
allwords = all.split()
for i in range(0,len(allwords)):
	if not "http://www.google.com" in allwords[i]:
 		allwords[i] = "xXx"
print ' '.join(allwords)
Output:
Code:
'xXx xXx http://www.google.com xXx xXx xXx'