-1

I have a school project that requires me to take values from a text document and send them to a different text document(In sorts just simplifying the text document). I need to be able to find lines with certain information(already done) and then take just the last value in that list. This is all coded with Python.

The value I'm taking is an IP address so it will always be an integer. However, some of the IP values have parenthesis around them and if possible I also need to remove just the parenthesis and keep the IP inside of them.

:for i, line in enumerate(searchlines):
    if "Nmap scan report for" in line:
        for l in searchlines[i:i+1]: IPlog.write(l)
        print:
  • The answer would depend, in part, on the language your are using, which you neglected to identify. – Scott Hunter May 15 '19 at 23:36
  • I'm still pretty new to all of this, my apologies. Its Python and I have now added that to the Tags and question. – William Pring May 15 '19 at 23:41
  • Can you give some sample input and output? What would be the values of `line`? – J...S May 16 '19 at 00:04
  • I have been given a text document with data such as "Nmap scan report for 137.87.208.5" or "Nmap scan report for bt213-w-01-s18.lcccms.msft (137.87.208.170)" there is other data but I'm looking for these lines. I have collected the data I need and sent it to a text document as seen above. The next step is to get rid of everything but the IP(which is always the last item in the list(. So currently I'm sending the entire line but only want to send the last item of the line, if that helps – William Pring May 16 '19 at 00:10
  • Possible duplicate of [Getting the last element of a list in Python](https://stackoverflow.com/questions/930397/getting-the-last-element-of-a-list-in-python) – Boris Verkhovskiy May 16 '19 at 00:13
  • Also this question https://stackoverflow.com/questions/29459008/how-to-remove-brackets-from-python-string for removing brackets – Boris Verkhovskiy May 16 '19 at 00:14
  • I guess you need to do this one first https://stackoverflow.com/questions/4309684/split-a-string-with-unknown-number-of-spaces-as-separator-in-python – Boris Verkhovskiy May 16 '19 at 00:16
  • @Boris I've voted to close this as Too Broad, since it asks for a complete solution combining many different tasks (parsing some unspecified file format, accessing the final element from the parsed result, doing further processing on the parsed result, outputing a particular result to a file, etc.) rather than breaking them down into individual tasks and researching how to perform each one. Solutions to most of the subtasks would be simple to find elsewhere, as you've demonstrated. – jpmc26 May 16 '19 at 02:46

1 Answers1

2

For displaying the last element of the list.

element = searchlines[-1]
element = searchlines[-1:] 
Sree
  • 1,694
  • 1
  • 18
  • 29