Let's say, one has stored the stdout of a shell command in a variable. Example for demonstration:
#!/usr/bin/python
import subprocess
proc = subprocess.Popen(['cat', '--help'], stdout=subprocess.PIPE)
output = proc.stdout.read()
Variable output
now holds content similar to this:
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
...
For complete documentation, run: info coreutils 'cat invocation'
How could one append something to each line besides the last line? So it looks like the following?
Usage: cat [OPTION]... [FILE]...<br></br>
Concatenate FILE(s), or standard input, to standard output.<br></br>
...<br></br>
For complete documentation, run: info coreutils 'cat invocation'
It would be possible to count the line numbers, to iterate through it, construct a new string and omit appending for the last line... But... Is there a simpler and more efficient way?