1756724 Members
2545 Online
108852 Solutions
New Discussion юеВ

Re: inserting delimiters

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor

Re: inserting delimiters

My solution is best explained by taking out all shortcuts:

$ perl -lpe'($u,$f)=split /\W/; $_=join q(,),$u,split(//,$f)'

Really is...

while ($line = ) {
($user, $flags) = split (/\W/, $line);
@letters = split(//, $flags);
$new_line = join ',' , $user, @letters;
print $new_line, "\n";
}

Hein.


cam9269
Regular Advisor

Re: inserting delimiters

appreciate your enthusiasm Steven! I picked up on your advice :)
Thanks for the notes Hein! Will likely to play and consider it in the code too

Cheers!
Dennis Handly
Acclaimed Contributor

Re: inserting delimiters

>Steven: As if that could stop me...
>echo 'user1,YNNNNNNNNN' | \
sed -e 's/,/ /' -e 's/\([NY]\)/\1 /g' -e 's/ /,/g' -e 's/,$//g'

It is obvious this isn't going to work if the user name is like "YESNO".

I'm also not sure why you want to change to spaces then back?
Note: the "g" in 's/,$//g' is useless.
cam9269
Regular Advisor

Re: inserting delimiters

i really, really appreciate all the inputs! :)
Dennis Handly
Acclaimed Contributor

Re: inserting delimiters

You can also use awk. Unfortunately I can't get split to work there with an empty RE.
awk -F, '
{
printf $1 ","
for (i=1; i < 20; ++i)
printf substr($2,i,1) ","
print substr($2,20,1)
} '