I have to remove the first 2 headers of many files and replace them with another one. As I am new to Python and programming, I have been using the following code
import glob
import os
list_of_files = glob.glob('./*.txt')
for file_name in list_of_files:
os.system('sed "1,2d" %s | sort -k1 > %s.sort' %(file_name,file_name))
os.system ('cat header file %s.sort > %s.header' %(file_name,file_name))
which works. However I think there should be a better way of getting this done. Also I am unnecessarily making an extra file *.sort which I don’t require.
Believe it or not, you can do this pretty easily in pure python:
You’re done. Take a slightly longer lunch break because python helps you save time* :-).
*(Alternatively, spend some of your long lunch learning more of the cool things python has to offer!)
Happy Coding!