ksh timestamp:
date '+%Y-%m-%d-%H.%M.%S.%N'
suggest to user timestamp rather than date value as the suffix of the the script logs because the date value could be duplicated within one day.
For example, script A exports data into a shared file and job B and C, which share the same load script, load the exported data into database, if the suffix of the target log is date, there will be collision.
The same example, if job B and C have different inputted table names, it is not suggest to put the table names into a file to handle, even if the file have timestamp as the suffix to avoid collision, because timestamp may be the same, too. Try to handle multiple values by array.
Writing to a shared file may lead to collision and better to store application private data into its own data structure.
ksh array
- indexed array
initiate:
set -A characters Mugen Jin Fuu
To print first value, enter:
echo ${characters[0]}
To count number of items in an array called characters, enter:
echo ${#characters[@]}
You can use for loop as follows to iterate through all values:
for i in ${characters[@]}; do echo "Samurai Champloo character - $i"; done
sed
sed -r -i.bkp -c "s/.*source_1.*/target_1\;/g;s/.*source_2.*/target_2\;/g"