I am processing a huge file. I want to search for a word in the line and when found I should print 10 lines before and 10 lines after the pattern match. How can I do it in P
Try this
#!/usr/bin/python import commands filename = "any filename" string_to_search = "What you want to search" extract = (commands.getstatusoutput("grep -C 10 '%s' %s"%(string_to_search,filename)))[1] print(extract)