Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline)
I use sed a lot to make scripting. If you perform the same tasks in your daily work, sed and curl will be the two of the most important tools you will need. Sed can be a bit complicated at the beginning but you will get used to it soon.
Replacing Text/Number/IP with Sed
It doesn’t need to be an IP but that’s just an example. You can look for a text/number or IP address in a document and once you find it (192.168.1.152), you can replace it with desire which is 192.168.10.13 in our case.
# sed -i 's/192.168.1.152/220.127.116.11/' exploit.py
Editing Certain Line with Sed
Let’s say that you would like to comment a certain line in your script and you can do with sed easily.
# sed -i '11 s/upload =/#upload =/' exploit.py
Another example, imagine a scenario you would like to comment all the lines start with socks4 in a document, what you can do is using:
# sed -e '/socks4/s/^/#/g' -i /etc/proxychains.conf
Add something to Certain Line with Sed
We are adding system(“whoami”) command to line 30 in the exploit.py file.
sed -i "30i system('whoami')" exploit.py