i wanted delete , replace first 3 lines of files in directory met condition. used following code:
test=find . -name "*.java" testing $test function testing{ var in $@ echo $var if head -3 $var | grep '^ \*$';then echo "in if" sed '1,3d' $var > tmp.java; mv tmp.java $var echo -e "/**\n* new text\n**/" | cat - $var > temp.java done }
the code works fine current directory files fails child directory files.
please let me know i'm going wrong.
your script hard read, replace first lines of code use sed command this
sed -i '1,3s/.*/replace_text/' java_file
your script should this
test=$(find . -name "*.java") testing $test function testing{ var in $@ echo $var if head -3 $var | grep '^ \*$';then echo "in if" sed -i '1,3s/.*/replace_text/' $var fi done }
Comments
Post a Comment