I’ve a large number of text files in a directory and want to cut and paste the first comment section to be at the start of the file (the length and start point of the comment text varies, in some cases it might not be present, but should be in first 50 lines). I’m thinking of using some bash code to work through all the files and then use sed on each filename to cut the first block of comment text enclosed between ''' and ''' to be moved to the top of file. I'm struggling with what i think needs to be a nested a sed command, initially using sed to find the matching block of text and then using the sed hold space. Ubuntu 23.04
Original sample:
from itertools import permutations
import time
'''
Here is some comment text
that should be at start of file
some more lines
'''
def somepythoncode(x):
return x+1
Target:
'''
Here is some comment text
that should be at start of file
some more lines
'''
from itertools import permutations
import time
def somepythoncode(x):
return x+1