search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

1 answers
Q&A linux - Write a script to modify the configuration information in the file, execution error

0

There are three main files test.cnf test.sh test.txt
Execute test.sh to read the configuration of test.cnf to modify the content of test.txt. During the execution, the configuration is read successfully but sed is executed. The time was not found.
sed is just debugging here without modifying test.txt, it just displays the results of test.txt

[root@localhost /tmp]# head -100 test*
==> test.cnf  test.sh  test.txt 

Execution errors are displayed during debugging;

[root@localhost /tmp]# bash -x test.sh
+ myconf
+ source test.cnf
++ yy=123
++ ppp=456
+ read myline
+ awk -F= '{print $1}' test.cnf
test.sh: line 4: s/{{$myline}}/${$myline}/g: bad substitution
Your Answer
submit

1 answers
0
 while read a b;do sed -n "s/$a/$b/p" test.txt;done < <(awk -F= '{print ,}' test.cnf)

Other methods:

awk -F= -vOFS='=' 'NR==FNR{a[]=;next}{for(i in a)if( ~ i)sub(i,a[i],)}1' test.cnf test.txt
2017-07-04 13:47:27

submit

Popular tool

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use