简体   繁体   中英

Scripting of File Edits in a Bash Shell

I have a large directory structure with many files named "configuration.txt". For each instance of configuration.txt that has directory "n10" somewhere in its path (and there are many such instances of this particular directory), I would like to do a search-and-replace where all instances of the string "DNSMax=20" gets replaced with string "DNSMax=50".

Please note that my path names contain spaces.

Could someone please give a Bash shell script that, if invoked from the root of my large directory structure, would accomplish this task?

I am using RedHat Linux.

Thank you!

Using find and GNU sed :

find / -path '*/n10/*' -name configuration.txt \
      -exec sed -i 's/DNSMax=20/DNSMax=50/' {} \;

如果完整文件路径之间没有空格,这将起作用。

find . -name "configuration.txt"|grep '\/n10\/'|xargs perl -pi -e 's/DNSMax=20/DNSMax=50/'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM