Monday 10 May 2010

*REFERENCE MATERIAL* - scripting basics

Looping through results of an ls command, and performing a copy / name change action on each one of those results:


Example:

for FILE in `ls *PP*ESB*.properties`; do cp $FILE `echo $FILE | sed 's/PP/LIVE/g'`; done


Explanation:

FILE is the token for each line returned from the command `ls *PP*ESB*.properties`. For each one of these results, the file is copied and the name changed from 'PP' to 'LIVE'