Add some specific word to some files using For Loop

We Need to add the line/change it from unlimited to 500 for MAX_EMAIL_PER_HOUR=500
for all packages/files under the folder.

Step 1
---------
cp -rpf /var/cpanel/packages /var/cpanel/packages_org
Step 2
--------
2).ls /var/cpanel/packages > test.txt

 #but we need to remove some files which have spaces[in between] from the list test.txt, then need to add the entry MAX_EMAIL_PER_HOUR=500 for that files manually. Because it does not recognize the spaces b/w single file.
E.G:
 johnhe3_WebFarm Beef(single file)
For loop consider it as two files johnhe3_WebFarm,Beef.

Step 3
--------
3).for i in `cat test.txt`; do if [ -z `grep -w 'MAX_EMAIL_PER_HOUR' "$i" | cut -d = -f1` ]; then echo -e 'MAX_EMAIL_PER_HOUR=500' >> "$i"; else sed -i 's/MAX_EMAIL_PER_HOUR=unlimited/MAX_EMAIL_PER_HOUR=500/g' "$i"; fi; done

Comments

Popular posts from this blog

KVM & Qemu

PHP Fatal error: Class 'JFactory' not found

docker.errors.APIError: 400 Client Error client is newer than server