LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Need to separate the following value 'xxx.xxx.xxx.xxx:xx:xx' (https://www.linuxquestions.org/questions/linux-general-1/need-to-separate-the-following-value-xxx-xxx-xxx-xxx-xx-xx-584706/)

SlowCoder 09-14-2007 03:32 PM

Need to separate the following value 'xxx.xxx.xxx.xxx:xx:xx'
 
I'm sure sed or awk will come into play here. But I can't figure 'em out!

I need to split a line of text, based on the first instance of colon ":".

For instance, if I have the line 'xxx.xxx.xxx.xxx:yy:zz' I want a return of both the left ('xxx.xxx.xxx.xxx'), and the right ('yy:zz').

Any help?

wjevans_7d1@yahoo.co 09-14-2007 04:05 PM

What language are you using? What did you try so far, and what happened?

anomie 09-14-2007 04:09 PM

One idea:
Code:

[mrbig]$ var=($(echo 'xxx.xxx.xxx.xxx:yy:zz' | sed 's/:/ /'))

[mrbig]$ echo ${var[0]}
xxx.xxx.xxx.xxx

[mrbig]$ echo ${var[1]}
yy:zz


carl0ski 09-14-2007 04:19 PM

another


Code:

var1=($(echo 'xxx.xxx.xxx.xxx:yy:zz' | cut -d ':' -f 1))
echo $var1

xxx.xxx.xxx.xxx


Code:

var2=($(echo 'xxx.xxx.xxx.xxx:yy:zz' | cut -d ':' -f 2,3))
echo $var2



All times are GMT -5. The time now is 02:56 PM.