text process in python
Question: I have data like this:

    
    
    value1
    something text
    something text
    

And I want to change the something text with the value. Example:

    
    
    value1
    value1
    value1
    


Answer: One way:

    
    
    import sys
    
    file = open('file','r')
    
    for line in file:
        if line.startswith('value'):
            pattern=line
        sys.stdout.write(pattern)
    

Save the script to `script.py` and run it with `python script.py`
_(where`script` is something descriptive)_.

    
    
    value1
    value1
    value1
    value2
    value2
    value3
    value3
    value3
    value3
    value3
    

And redirect the output `python script.py > new_file`

