0

This question already has an answer here:

There is a file named partner like:

abc
def
ghi

There is another conf file like:

part=abc
var=x
var=y
id=123

part=def
var=z
id=345

and so on...

I am making a shellscript which reads line from 'partner' using while loop, then searches the block containing that partner name in conf file using sed. After that, and finally replacing id value (eg: from 123 to 123_1 )using sed and storing the new block in another file.

while read -r var || [[ -n "$var" ]]
do sed -n '/part=$var/,/^$/p' conf.cfg | xargs sed 's/id=123/id=123_1/g' >> new.txt
done

What am I doing wrong? As it only gives me empty lines of text as output.

marked as duplicate by Rui F Ribeiro, Dmitry Grigoryev, Jeff Schaller, Eric Renouf, HalosGhost Dec 2 '16 at 14:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

When using variables in arguments of a command, you can't enclose it in simple quotes.

Troubleshooting shell scripts, try running your commands one after the other, ... this would help you narrow down your problem.

sed -n "/part=$var/,/^$/p" conf.cfg
  • 1
    Thanks SYN.. That was helpful. There was double-quote problem in the sed command. Other than that the real issue was in file itself (LF and CRLF). Command dos2unix did the trick. – Arjit Dixit Dec 5 '16 at 8:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.