Mailinglist Archive: opensuse (4053 mails)

< Previous Next >
RE: [SLE] splitting a string
  • From: (Ted Harding) <Ted.Harding@xxxxxxxxxxxxxxxx>
  • Date: Thu, 09 Aug 2001 15:24:35 +0100 (BST)
  • Message-id: <XFMail.010809152435.Ted.Harding@xxxxxxxxxxxxxxxx>
> S.Toms writes:
> > Quick question for everyone, I want to beable to split a string
> that contains a colon at the colon, for example
> >
> > 4.23.242.12:2323

If it's in a line in a file,

cat file | awk 'BEGIN{FS=":"}{print $1}'

assuming there are no other lines with colons where you don't want
this to happen. Otherwise you're getting into heavier regular
expression things, e.g.

'BEGIN{FS=":"} {if($0 ~ /[0-9.]+[0-9]+:/)print $1 ; else print $0}'

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding@xxxxxxxxxxxxxxxx>
Fax-to-email: +44 (0)870 167 1972
Date: 09-Aug-01 Time: 15:24:35
------------------------------ XFMail ------------------------------

< Previous Next >
References