Pages

Script to Replace a Word

Script to Replace a Word

This script will help you to understand how to replace a word in a file...........
Now we are going to replace "ONBOOT=no" to "ONBOOT=yes" in the file /etc/sysconfig/network-scripts/ifcfg-eth0.....
Create a file




#vi test.sh

#!/bin/bash
OLD="ONBOOT=no"
NEW="ONBOOT=yes"
DPATH="/etc/sysconfig/network-scripts/ifcfg-eth0"
for f in $DPATH
do
if [ -f $f -a -r $f ]; then
        sed "s/$OLD/$NEW/g" "$f"
else
        echo "Error: Cannot read $f"
fi
done



:wq!  ------------>   save and exit file

#chmod   u+x    test.sh  ------------> give excute permission


# /root/test.sh  -----------> run the script


You can also use the below command to complete the above task









or use the command
perl -p -i -e 's/ONBOOT=no/ONBOOT=yes/g;' /etc/sysconfig/network-scripts/ifcfg-eth0



17 comments:

  1. Thanks combination of suitable and useful information and well-written sentences that will certainly entice your sense.There are so multiple comments here that are really entertaining and conducive to me thanks for sharing a link especially for sharing this blog.
    piedmontreal-estate |

    ReplyDelete
  2. I just wanted to let you know that what you do really affects peoples lives and that people - like me - truly appreciate it.
    www.lowermyautorate.com |

    ReplyDelete
  3. I was suggested this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are wonderful! Thanks!
    www.r2automation.com |

    ReplyDelete
  4. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work
    http://www.vpmautogb.com |

    ReplyDelete
  5. A good informative post that you have shared and appreciate your work for sharing the information.
    http://www.cardiologiefitness.com |

    ReplyDelete
  6. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained!
    biketowork2013 |

    ReplyDelete
  7. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value. Im glad to have found this post as its such an interesting one! I am always on the lookout for quality posts and articles so i suppose im lucky to have found this! I hope you will be adding more in the future..
    lincolnmaineusa |

    ReplyDelete
  8. I've seen your awareness about this theme whenever you post it and it really gives an informational message to us readers. I am hoping that you'll continue writing this kind of blog. Thanks for sharing this information.
    http://www.okhomewindows.com |

    ReplyDelete
  9. I am trying to implement your solution but i am getting a stack overflow error at line 403, I presume this is in the jester.js file but I am not sure why it is happening.
    www.c3caregiver.com |

    ReplyDelete
  10. Between me and my husband we’ve owned more MP3 players over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I’ve settled down to one line of players. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.
    notchfood.com |

    ReplyDelete
  11. However, sumptuous texture and exquisite craftsmanship will not be covered by this simple dressing. It will be dazzling to accent your high-end taste
    www.serenelovingcare.com |

    ReplyDelete
  12. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. 
    http://www.execu-car.com |

    ReplyDelete

Note:- Comment as: Option available to post without login select "Anonymous" from the drop down...........