Hi,
I have file with text
________________________________
GROUP:firstname1.lastname1,first_name2.last_name2,first_name3.last_name3
HEAD:firstname.lastname
________________________________
I need help to pick the names separately ie..
Need out put
as
var1 =firstname1.lastname1
Var2=first_name2.last_name2
..
var n=firstname.lastname
or keep them in a array
array[names]
Please help
sb008
August 28, 2009, 2:04pm
2
for ENTRY in `grep -i group <file> | cut -f2 -d: | tr ',' '\012'`; do echo $ENTRY; done
replace "echo $ENTRY" by whatever suits ur needs, e.g.
ARRAY[$INDEX]=${ENTRY}
((INDEX=${INDEX}+1))
line=GROUP:firstname1.lastname1,first_name2.last_name2,first_name3.last_name3
data=${line#GROUP:}
IFS=, read -a array <<. ## Bash; use -A for ksh
$data
.
perl:
my @arr;
open FH,"<a.txt";
while(<FH>){
chomp;
my @tmp=split("[:,]",$_);
@arr=(@arr,@tmp[1..$#tmp]);
}
print join "\n", @arr;
rider29
September 2, 2009, 10:12am
5
sb008:
for ENTRY in `grep -i group <file> | cut -f2 -d: | tr ',' '\012'`; do echo $ENTRY; done
replace "echo $ENTRY" by whatever suits ur needs, e.g.
ARRAY[$INDEX]=${ENTRY}
((INDEX=${INDEX}+1))
I have a small problem, Instead of text file, I have the text coming as an o/p of an other script i.e something similar to
for ENTRY in `/workspace/script3.sh "$arg1" |grep -i group |
cut -f2 -d: | tr ',' '\012'`;
but I don't see the same result as the original code. Please can you correct me?