Timeline for Split string into array and print each element on a new line with commandline
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 3, 2016 at 5:05 | vote | accept | danielr1996 | ||
| Feb 2, 2016 at 22:01 | comment | added | Costas | @glennjackman Yes, you are right. | |
| Feb 2, 2016 at 21:50 | comment | added | glenn jackman |
@Costas, hmm, what if there's a space within a field? tr -s ', ' '\n' will split the field into multiple lines.
|
|
| Feb 2, 2016 at 21:42 | answer | added | tink | timeline score: 6 | |
| Feb 2, 2016 at 21:19 | comment | added | Costas |
line="a,b,c,d,e,f" ; echo -e ${line//,/\\n}
|
|
| Feb 2, 2016 at 21:15 | comment | added | Costas |
@glennjackman tr -s ', ' '\n'
|
|
| Feb 2, 2016 at 21:03 | comment | added | Costas |
IFS=',' read -a array <<<"a,b,c,d,e,f" ; printf '%s\n' "${array[@]}
|
|
| Feb 2, 2016 at 21:00 | history | edited | danielr1996 | CC BY-SA 3.0 |
deleted 5 characters in body
|
| Feb 2, 2016 at 20:58 | history | edited | danielr1996 | CC BY-SA 3.0 |
added 92 characters in body; deleted 101 characters in body
|
| Feb 2, 2016 at 20:54 | comment | added | glenn jackman |
I'm not clear what you're really asking. You can translate commas to newlines with "tr": echo a, b, c, d | tr , '\n' -- that leaves spaces at the start of the b/c/d lines.
|
|
| Feb 2, 2016 at 20:51 | history | asked | danielr1996 | CC BY-SA 3.0 |