I've got a string like this:
8080 "ac ac df asd" 9019 "f v adfs" 1 "123 da 123x"
Is there a clever way to convert this into arrays like this using Bash?
8080 "ac ac df asd"
9019 "f v adfs"
1 "123 da 123x"
I've got a string like this:
Is there a clever way to convert this into arrays like this using Bash?
|
|||||||||
|
Output: "8080" "ac ac df asd" "9019" "f v adfs" "1" "123 da 123x" |
||||
|
This will split your values into separate array items, which you can then join. I'm sure there's a better way but this delivers the output you've requested from the input you've provided. If this is user input (or if it's input outside your control) the following solution should not be used in case backticks or variable substitutions are offered to the
This code assumes that the second of each pair requires quotes (they are removed during the |
||||
I think this is what you want, assuming it's OK to use Example
The approach you're looking for is to recognize a pattern and replace it with a newline character,
In those situations we want to put a |
||||
|