Tuesday, May 22, 2012

Repeatable file changes made easy with SED command in Linux

Using sed command we can add desired text at desired line in a file. That can be a comment, description or anything.

The below code inserts the comment text at the line 2 at each PHP  file inside the current directory.


    for fileItem in ./*.php
        echo "Updating file : $fileItem"
        sed '2i\//      Author: Senthilkumar C' $fileItem > tmp.php
        cp tmp.php "$fileItem"
    #remove temp file
    rm tmp.php

No comments:

Post a Comment