0
  • I am getting some linewise output from grep like ...
value1
value2
value3
  • in order to filling a variable for a bash script I need to transform this into inline format like ('value1' 'value2' 'value3') though.

In reality there are more then 40 values, so I am looking for an automated workflow rather then just doing it manually.

how would I go about this?

2 Answers 2

1

Simply pipe your output to something like:

sed "s/$/\'/"  | sed "s/^/\'/" | tr  '\n' ' ' ;echo
1
  • in order to filling a variable for a bash script I need to transform this into inline format like ('value1' 'value2' 'value3') though.

To fill an indexed array variable with lines from the output of a grep command in bash, you can use the readarray (aka mapfile) shell builtin:

readarray -t arr < <(grep [OPTION...] PATTERNS [FILE...])

Adding literal quotes is not necessary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .