I have a text file that I want to search for a specific ip address, and the way the text file is set up is that the host name is above the ip add. ie
real HOSTNAME
address xx.xx.xx.xx
What is the best/simplest way to go about getting the hostname when I only got the ip address to search on? Regular expressions? Is there a sed like utility in python that has a hold space? Any help is appreciated thanks
If you know how many lines the hostname is before the ip then you could enumerate a list of lines, and subtract the necessary number of lines from the current index: