Results 1 to 10 of 15
hi all
i would like split this
ID=123:one=a:two=a@yahoo.com:three=789:four=:five= 123
i tried this
Code:
echo "ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123" | sed 's/\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):.*$/\/\/begin\
\
\
/'
but showing out put like this
[root@localhost giis4.1]# echo ...
- 04-11-2007 #1Linux Newbie
- Join Date
- Feb 2007
- Location
- hyderabad, india
- Posts
- 247
how to split
hi all
i would like split this
ID=123:one=a:two=a@yahoo.com:three=789:four=:five= 123
i tried this
i wanna output likeCode:echo "ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123" | sed 's/\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):.*$/\/\/begin\ \2\ \4\ \6/' but showing out put like this [root@localhost giis4.1]# echo "ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123" | sed 's/\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):\(.*=\)\(.*\):.*$/\/\/begin\ > \2\ > \4\ > \6/' '//begin 123 a a@yahoo.com [root@localhost giis4.1]#
//begin
a
a@yahoo.com
789
123
in this four has blank
coz, it has no number.
how can can i get this
please help me
thank you in advance
- 04-11-2007 #2
I like sed and use it liberally but I would use cut and a bit of logic for this:
RegardsCode:count=1 test="ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123" while [ `echo $test | cut -d: -f$count` ] do both=`echo $test | cut -d: -f$count` first=`echo $test | cut -d: -f$count | cut -d= -f1` second=`echo $test | cut -d: -f$count | cut -d= -f2` if [ $first == "ID" ] then echo "//begin" else echo $second fi count=$((count + 1)) done
- 04-11-2007 #3Linux Newbie
- Join Date
- Feb 2007
- Location
- hyderabad, india
- Posts
- 247
thank you for quick replay
if i take like this
Originally Posted by birdman
it is not printing any messages.
it has to be print like this
//begin
a
a@yahoo.com
789
123
//begin
b
b@yahoo.com
.........
.......
.......
like this
can you help me in this way
thank you in advance
- 04-11-2007 #4Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
reply
count=1
test="ID=123:one=a:two=a@yahoo.com:three=789:four= :five=123"
while [ -n "$( echo $test | cut -f$count -d':' )" ]
do
x=$( echo $test | cut -f$count -d':' )
if [ "$count" -eq 1 ]
then
echo Begin
x=$( echo $x | cut -f2- -d'=' | cut -b2- )
echo $x
else
x=$( echo $x | cut -f2 -d'=')
echo $x
fi
((count=count+1))
done
- 04-11-2007 #5Linux Newbie
- Join Date
- Feb 2007
- Location
- hyderabad, india
- Posts
- 247
thank you for quick replay
it giving output like this
Originally Posted by Saurabh0008
Begin
23
a
a@yahoo.com
789
123
i no need of getting "23" after Begin.
and the in must be
test="ID=123:one=a:two=a@yahoo.com:three=789:four= :five=123
one=b:two=b@yahoo.com:three=9:four=1:five=23
one=c:two=c@yahoo.com:three=7:four=:five=12
one=d:two=d@yahoo.com:three=:four=1:five=13
:/"
can you help me
thank you in advance
- 04-11-2007 #6Linux Newbie
- Join Date
- Feb 2007
- Location
- hyderabad, india
- Posts
- 247
thank you for quick replay
hi
i tried this also
it is giving output likeCode:count=1 test="list=S$ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123 ID=123:one=b:two=b@yahoo.com:three=9:four=1:five=23 ID=123:one=c:two=c@yahoo.com:three=7:four=:five=12 ID=123:one=d:two=d@yahoo.com:three=:four=1:five=13" while [ -n "$( echo $test | cut -f$count -d':' )" ] do x=$( echo $test | cut -f$count -d':' ) if [ "$count" -eq 1 ] then echo Begin x=$( echo $x | cut -f2- -d'=' | cut -b3- ) echo $x else x=$( echo $x | cut -f2 -d'=') echo $x fi ((count=count+1)) done
i wanna have output like[root@localhost ~]# /root/Desktop/1234/ram4
Begin
123
a
a@yahoo.com
789
123 ID
b
b@yahoo.com
9
1
23 ID
c
c@yahoo.com
7
12 ID
d
d@yahoo.com
1
13
[root@localhost ~]#
can you help meBegin
a
a@yahoo.com
789
123
Begin
b
b@yahoo.com
9
1
23
Begin
c
c@yahoo.com
7
12
Begin
d
d@yahoo.com
1
13
thank you in advance
- 04-11-2007 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
One way to approach this in perl:
Which produces:Code:#!/usr/bin/perl # @(#) p1 Demonstrate non-greedy perl match. use warnings; use strict; my ($lines) = 0; my ( $i, $j, @a ); while (<>) { $lines++; @a = (); s/$/:/; # add closing delimiter (@a) = /.*?=(.*?):/g; # extract =(anything): $j = 0; $a[0] = "Begin"; # replace first element foreach $i (@a) { print $i, "\n"; $j++; } } print STDERR " ( Lines read: $lines )\n"; exit(0);
Best wishes ... cheers, drlCode:% ./p1 data1 Begin a a@yahoo.com 789 123 Begin b b@yahoo.com 9 1 23 Begin c c@yahoo.com 7 12 Begin d d@yahoo.com 1 13 ( Lines read: 4 )
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 04-12-2007 #8Linux Newbie
- Join Date
- Feb 2007
- Location
- hyderabad, india
- Posts
- 247
thank you for quick replay
i tried
Originally Posted by munna_dude
output is
[root@localhost ~]# /root/Desktop/1234/pearl1 /root/Desktop/1234/filename.txt
Begin
Begin
a
a@yahoo.com
789
123
Begin
b
b@yahoo.com
9
1
23
Begin
c
c@yahoo.com
7
12
Begin
d
d@yahoo.com
1
13
( Lines read: 5 )
[root@localhost ~]#
Begin coming two times (at first line),
can u help thank you in advance
- 04-12-2007 #9Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I used this data set:
Please post the data set you used ... cheers, drlCode:ID=123:one=a:two=a@yahoo.com:three=789:four=:five=123 ID=123:one=b:two=b@yahoo.com:three=9:four=1:five=23 ID=123:one=c:two=c@yahoo.com:three=7:four=:five=12 ID=123:one=d:two=d@yahoo.com:three=:four=1:five=13
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 04-12-2007 #10Just Joined!
- Join Date
- Apr 2007
- Posts
- 5
reply
hi,
i would like to know whether ur i/p is from a file or from the terminal.and secondly is $test getting single values i.e "id=123........................................... ........:five=...." .


Reply With Quote