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.

  • 5
  • The commands are working fine in shell for one partner, but i need to use while loop so when i added it in script it is not working anymore. So, i guess issue is something else – geek Dec 2 '16 at 13:31
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
| improve this answer | |
  • 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 5 '16 at 8:50

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