Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1389  / 1 Year ago, fri, march 3, 2023, 3:49:56

I have below command to find all the .xml files containing the <active>true</active> having <codePool>community</codePool> after that line on next line.



grep -rzl '<active>true</active>.*<codePool>community</codePool>' --include='*.xml' --color=always


Now how to combine this with sed to replace true string inside the <active>... tag to false string along those matched lines ?


More From » 14.04

 Answers
3

Thanks for the answer @glennjackman, I was also successfull achieving my requirement with the following code, it is vulnerable in-case the input changes, but it will be consistent keeping the fixed directory structure and file format of xml files of Magento, in mind:



for filename in *.xml; do
if grep -q '<codePool>community</codePool>' "$filename"; then
if [[ $filename != *"Mage_"* ]]; then
sed -i.bak 's/<active>true</active>/<active>false</active>/g' "$filename"
fi
fi
done


This way I was also able to backup those files first, that were going to be modified, just the way I wanted.



Hope this simplifies things and redirects all/as many as possible people to using domestic libraries rather than installing third party tools which aren't allowed to install on Remote SSH/VPN networks.


[#13089] Sunday, March 5, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
velelf

Total Points: 395
Total Questions: 115
Total Answers: 107

Location: Sudan
Member since Mon, Jun 1, 2020
4 Years ago
;