Skip to main content
deleted 5 characters in body
Source Link
danielr1996
  • 505
  • 2
  • 4
  • 12

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

How can I get this output

a
b
c
d
e
f

from this input

a, b, c, d, e, f

?

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

How can I get this output

a
b
c
d
e
f

from this input

a, b, c, d, e, f

?

I'm having a String which is seperated by commas like a,b,c,d,e,f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a,b,c,d,e,f" | awk -F', ' '{print $i"\n"}'

How can I get this output

a
b
c
d
e
f

from this input

a,b,c,d,e,f

?

added 92 characters in body; deleted 101 characters in body
Source Link
danielr1996
  • 505
  • 2
  • 4
  • 12

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

But it only prints the elements followed by a newline. How can I use a for loop in awk to iterate over one line as an arrayget this output

a
b
c
d
e
f

from this input

a, b, c, d, e, f

?

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

But it only prints the elements followed by a newline. How can I use a for loop in awk to iterate over one line as an array?

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

How can I get this output

a
b
c
d
e
f

from this input

a, b, c, d, e, f

?

Source Link
danielr1996
  • 505
  • 2
  • 4
  • 12

Split string into array and print each element on a new line with commandline

I'm having a String which is seperated by commas like a, b, c, d, e, f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm having is that all cli tools I know so far(sed, awk, grep) only work on lines, but how do I get a string into a format that can be used by these tools. What i'v tried so far is

echo "a, b, c, d, e, f" | awk -F', ' '{print $i"\n"}'

But it only prints the elements followed by a newline. How can I use a for loop in awk to iterate over one line as an array?