Friday, 9 September 2022

sed Search and Replace with forward slash "/"

I always enjoy performing search and replace using sed command when I need to edit the same thing over multiple files. Usually the syntax that I use is as follow:

sed -i 's/search/replacement/' *.txt

This will replace all the word "search" with "replacement" in all files that ended with txt. 

But what if you want to replace the word "search" with "replace/ment". You just need to do minor adjustment as follow:

sed -i "s|search|replace/ment|" *.txt

Usually I omit the "-i" first to see the changes on the screen to make sure that the text are replaced properly before adding "-i" to perform the actual changes. 

Until next time!!! 

Wednesday, 7 September 2022

SSH Tunneling - Simple localhost port forwarding

 Recently I saw an application that run on 127.0.0.1 port 8080 on the server that I need to access from my workstation. The easiest way to access this is to use ssh tunneling. 


To tunnel remote port to local machine, you can just perform the following:

ssh -g -L 9999:localhost:8080 -f -N username@remoteip


This will allow your local machine port 9999 to be tunneled to the remote machine application on port 8080


Launch your browser and login to http://localhost:9999 and you will be accessing the application running on the server localhost.   


Until next time :)