I needed to delete all the lines in a set of files except for for the first forty. Since the number of files was big, I used this script in python to do the job: -------------------------------- !/usr/bin/python #script to read files and delete lines import os listing=os.listdir(" /home/kjoshi/Documents/PY/useful/file_edit ") for infile in listing: print infile if infile == "files_line_delete.py": print "This is NOT a good file" else: fi=open(infile).readlines() fo=open(infile +'_output','w') del fi[40: ] fo.writelines(fi) --------------------------------- Task is simple. Keep all the files needed to be edited in one folder along with this script. Substitute the path shown in bold with proper path of your folder. Using command $python files_line_delete.py you get output files with each file having first forty lines.
Find some interesting facts,methods, basics in Computational Chemistry