Issue
I have an input file like below, its a config file so not a valid shell-script format(format-1):
DATA_DB=foo \
bar \
zoo
#may be a comment or not(unreliable content)
Sometimes, the format(format-2) could be as simple as:
DATA_DB=foo1
How, can I extract foo, bar, and zoo from this? I tried sourcing foo.cfg
but it didn't work as the values on RHS are not quoted.
Tried using while loop -r
but it either work for RHS or LHS.
while IFS='=' read -r key val; do echo "$val" ;done < foo.cgf
foo \
How to extract foo
, bar
and zoo
from format-1, while the same code should extract foo1
from format-2?
Solution
Using any awk:
$ awk '
sub(/^DATA_DB=/,"") { f=1 }
f { if ( sub(/\\$/,"") ) { vals=vals $0 OFS } else { $0=vals $0; $1=$1; print; exit } }
' file
foo bar zoo
Answered By - Ed Morton Answer Checked By - Terry (WPSolving Volunteer)