Bash Script
Creating a bash script where im reading the following line from a text file: "192.168.1.1:1092" I want it to read that and have it split into two variables: IP and Port, using the ":" as a separator.
It would be nice to not have two awk statements, sed or cut. Any help would be greatly appreciated. |
You're invited to post any (pseudo) code you've got together with any errors to receive possibly constructive comments.
|
I am with unSpawn, you show us what you have and where you are getting stuck (even if that is your 2 awk / other commands) and we will help you further.
|
Code:
j=0 Another way to go about it is: Code:
ip=$(echo "192.168.0.1:25" | cut -d: -f1) P.S. I thought your post was very clear and you showed your work by mentioning awk, sed and cut. |
buf=192.168.0.1:25
IP=${buf%%:*} port=${buf##*:} |
This can be done without the use of sed, awk or cut.
Just read up on Internal Field Separators. |
Thanks to everyone that posted helpful solutions. It is greatly appreciated!
|
Thanks janhe. Much appreciated for the excellent help.
Quote:
|
Thanks Catkin. I'm going to give this one a try also. Thanks!
Quote:
|
Code:
# buf=192.168.0.1:25 |
All times are GMT -5. The time now is 07:26 AM. |