Splitting a string on delimeter

how can i turn this:

A,a1,a2,a3
B,b1,b2


into this:

A,a1
A,a2
A,a3
B,b1
B,b2

using whatever tool works (bash/sed/python/excel...)
all the elements are strings (of variable length)

Ask your professor.

transform it into a list, and then break the list in half when you encounter the delimiter

Sauce me

i don't follow

that's a hot bitch

Sup Forums.c
#include
#include

int main() {
char str[128], *p;

printf("In: ");
scanf("%s", str);

p = strtok(str, ",");
while (p != NULL) {
puts(p);
p = strtok(NULL, ",");
}

return 0;
}


gcc Sup Forums.c

Photoshop tutorial.
Cut every string into a new layer.
Duplicate A and B as many times needed.
Rearrange everything.
Merge layers visible.

You could do it in bash easily

this is a problem for search engines

i can split a string on a delimiter easily, but don't know how to duplicate the A and B across multiple rows

perl -lne '@a=split /,/;$a=shift @a;print "$a,$_" for @a'

Are you a wizard™?

Are you fucking retarded? Please keep stupid questions in /sqt/. Do your own homework.

thanks, but it doesn't duplicate the first element. your code does this:

> In: A,a,b,c,d
A
a
b
c
d

I am trying to do this:

> In: A,a,b,c,d
A,a
A,b
A,c
A,d

that works, thanks!
i don't know perl. is there a way to feed it a text file?

I have no idea how the fuck this works but this is one of the most beautiful things I've seen.

perl -lne '@a=split /,/;$a=shift @a;print "$a,$_" for @a' input.txt

A game: pipe /dev/random into a tr command that that makes the output ascii, then try to determine what the resultant perl program would do.

thank you perl wizard

oh i missread OP

#include
#include

int main() {
char str[128], *p;

printf("In: ");
scanf("%s", str);

char a[32];
p = strtok(str, ",");
strcpy(a, p);
while ((p = strtok(NULL, ",")) != NULL)
printf("%s,%s\n", a, p);

return 0;
}

sweeeet

liek this?
$ cat input.txt
A,a1,a2,a3
B,b1,b2,b3
$ awk -F "," '{i=1;while(i++

Who the cum dump

...

I'd like to split her string on my delimiter if you know what I mean.

leanr how to use your libraries

Not thread safe

Why in gods name would you make this thread safe?

public static void splitWithDelimeters (String s1, String s2) {
String[] splitS1 = s1.split(",");
String[] splitS2 = s2.split(",");

for (int i = 1; i < splitS1.length; i++) {
System.out.println(splitS1[0] + "," + splitS1[i]);
}

for (int i = 1; i < splitS2.length; i++) {
System.out.println(splitS2[0] + "," + splitS2[i]);
}
}


Output:
A,a1
A,a2
A,a3
B,b1
B,b2

It's probably explained in your textbook you lazy piece of shit.

Awk would make that so fucking easy

UNIX FTW!

>perl -lne '@a=split /,/;$a=shift @a;print "$a,$_" for @a'
teach me how to specify the input feed for this so I can like you more

...

When I try to golf it
perl -F',' -lE'say"$F[0],$F[$_]"for 1..$#F' input.txt

I'm writing my first few shit programs in C.

It's printing text using printf, but i want the text to slowly appear on the screen for dramatic effect. How do I do this without making a printf and delay for every character?

You can't. But what you could do is make the code appear a little neater by storing the entire string in a char* array, then using a while() loop to loop through all characters in the array.

So something like this:
char* str = "hello";
char* c = str;
while(*c != '\0'){
printf("%c");
usleep(DELAY);
c++;
}
Just don't use it with arbitrary input, the string has to be null-terminated. And obviously you'll have to look into which type of delay function fits your intentions best.

$ perl -MO=Deparse -lne '@a=split /,/;$a=shift @a;print "$a,$_" for @a' g_zk.txt
BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = )) {
chomp $_;
@a = split(/,/, $_, 0);
$a = shift @a;
print "$a,$_" foreach (@a);
}

data = open("temp", "r").read()
for line in data.split("\n"):
line = line.split(",")
for x in line[1:]:
print(line[0] + "," + x)


Don't they teach this shit in middle school now?

gnu's not unix