File: string-replace.py

package info (click to toggle)
trilinos 16.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 994,012 kB
  • sloc: cpp: 3,764,859; ansic: 425,011; fortran: 160,684; python: 101,476; xml: 74,329; sh: 37,044; makefile: 22,641; perl: 7,525; f90: 6,424; csh: 5,285; objc: 2,620; lex: 1,646; lisp: 810; yacc: 603; javascript: 552; awk: 364; ml: 281; php: 145
file content (19 lines) | stat: -rwxr-xr-x 368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/env python
#

import sys

string_to_replace = sys.argv[1]
repalcement_string = sys.argv[2]
file_name = sys.argv[3]

with open(file_name, 'r') as file:
  lines = file.readlines()

newLines = []
for line in lines:
  line = line.replace(string_to_replace, repalcement_string)
  newLines.append(line)

with open(file_name, 'w') as file:
  file.writelines(newLines)