How to make a single change to multiple files
I have to make a single change to 250 files under same directory.
All the 250 lines are sh files which contain a version number. I have to update this version number in all 250 files. Can sed command be used to do it in a shot or do I need to write a script for this? Please help. OS : Linux- RHEL 7 Thanks in advance. |
sed itself can do the change and you need to write a loop on the list of files you have
|
So the following command should work?
sed -i 's/5.9/5.10/g' filename Can you please help me with the loop part? |
"filename" can be a glob.
Create a test directory with a few files. Easy to test and make sure you don't change things you didn't mean to. |
Quote:
http://www.thegeekstuff.com/2011/07/...loop-examples/ |
sed is good. perl works too. You can also do it with a perl one-liner:
Code:
perl -pi.orig -e 's/old/new/' *.txt s/// takes all the arguments that perl supports and can be written as s||| or s### if you need to use slashes. |
You need to be cautious with your current regex as it will match more than intended:
Code:
5.9 Try to look to see what makes the line unique, like does the line contain the word 'version' (capitalised or otherwise). |
All times are GMT -5. The time now is 12:47 PM. |