Artificial intelligent assistant

How to substitute a block of lines inside a file? I want to change the multi-line contain `foo2` to be like desired output `foo2` is like an array in multiline, how to change it to be in one line * **FROM:** $ cat file.txt foo1=bar1 foo2=('bar10: some text here' 'bar11: anther text here' ... 'bar: final text here') foo3=('bar3') foo=1.2.33 * **TO:** foo1=bar1 foo2="bar10 bar11 .. bar" foo3=('bar3') foo=1.2.33

Using any awk in any shell on every Unix box and assuming that `...` line in your input and `..` string in your output don't literally exist in your real data and are intended to represent text similar to the text around them:


$ cat tst.awk
(val=="") && /.*\047$/ {
tag = $0
sub(/=.*/,"",tag)
val = ""
}
tag != "" {
split($0,f,/[\047:]/)
val = (val == "" ? "" : val " ") f[2]
if ( /\)$/ ) {
print tag "=\"" val "\""
tag = ""
}
next
}
{ print }



$ awk -f tst.awk file.txt
foo1=bar1
foo2="bar10 bar11 bar"
foo3=('bar3')
foo=1.2.33

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 17e29ce8916160fb44191e5aea8b02ce