LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-14-2007, 03:32 PM   #1
SlowCoder
Senior Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Debian based
Posts: 1,250

Rep: Reputation: 164Reputation: 164
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?
 
Old 09-14-2007, 04:05 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
What language are you using? What did you try so far, and what happened?
 
Old 09-14-2007, 04:09 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
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
 
Old 09-14-2007, 04:19 PM   #4
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
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

Last edited by carl0ski; 09-14-2007 at 04:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error, some other host already uses address xxx.xxx,xxx,xxx ryan462 Linux - Networking 20 01-24-2010 11:14 PM
smbclient -M xxx.xxx.xxx.xxx Doesnt Work DiscreetControl Linux - Networking 7 12-28-2007 10:50 AM
Problem getting connection with a DLink Router with IP 10.xxx.xxx.xxx kezira Fedora 9 11-28-2005 10:31 PM
Problem getting connection with a DLink Router after setting static IP 10.xxx.xxx.xxx kezira Linux - Networking 1 11-09-2005 10:27 PM
Host XXX.XXX.XXX.XXX is not allowed to connect to this MySQL server ocavid Linux - Newbie 2 03-16-2005 09:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration