0

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.

geek
  • 13

1 Answers1

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
SYN
  • 2,863
  • 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. – geek Dec 05 '16 at 08:50