I am looking to extract a dynamic port number from a text file and print it in to a new text file.
The surrounding text stays the same.
Currently I am using:
sed -n '89p' originalfile.txt | cut -c 16- > newfile.txt
Line 89 of originalfile.txt is:
Forwarded port 12345
and then newfile.txt only contains that 5 digit number.
This has been working, except some times the line number changes from 89 to something else, and I was looking for a more permanent solution?
Another piece of text in originalfile.txt is this, which may be better to use:
--> The port is 12345 and it will expire on 2024-08-28T23:50:18. <--
Thank you
cliny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.