missing ; before statement

To check Javascript error, use Firefox Web Developer Addon

Tool -> Error Console

Got javascript error as “missing ; before statement” although there was no missing “;”

Finally found the reason is that the javascript function used number at the beginning, like

2way_func = function(){ …..}

awk & Sed

Calculate sum of the file size

ls -l access_log.2008-12-20*|gawk ‘{a+=$5;} END {print a;}’

 

Edit special lines using regular expression

awk ‘/aaa/ ‘ filename

 

Change file names using sed

##Example: from access_log.2008-12-20.01.gz.1  to access_log.2008-12-20.01.1.gz

for file in `ls access_log.2008-12-20.*`

do

newname=`echo $file|sed ‘s/\(access_log.2008-12-20.[0-9][0-9]\).gz.\([0-9]*\)/\1.\2.gz/’`

size=`ls -l $file|awk ‘{print $5}’`

if [ $size -gt 100 ];then

  echo “$file-> $newname”

fi

mv -v $file $newname

done

Arrays in PHP

To define an Array

$prod = array();
$prod = array(“a”,”b”,”c”);

$prod = array(
“prod1” => array(“id”=>”prod001″,”date” => “111208”, “name”=>”aaa”);
“prod2” => array(“id”=>”prod002″,”date” => “111108”, “name”=>”bbb”);
“prod3 => array(“id”=>”prod003″,”date” => “111008”, “name”=>”ccc”);
);

$data=array();
$data[‘id’] = 1;
$data[‘name’] = ‘John’;

To read values out

foreach($SITE as $key1 => $val1){

foreach($sval1 as $key2 => $val2){

if($key2==”id”) echo “ID: $val2[0]\n”;

}

}

foreach($data as $value){

echo $value.”\n”;

}

Push elements into Array

bash — if

#!/bin/bash

if [ -n “$1” ]; then
        filename = $1;
else
        filename = `date –date=’1 hour ago’ “+%Y-%m-%d.%H”`;
fi

Compare numbers with -gt -lt -ne -eq

if [ “${size}” -gt 100 ];then
  echo $size
fi

Compare strings with = !=

if [ “${domain}” = “lalife.net” ];then
echo “correct”
fi
(#if [ “${domain}”=”lalife.net” ];then (##this won’t work without space around “=” or “!=”)

When using [[ ]]
if [[ ${domain} = “lalife.net” ]];then
echo “correct”
fi

([ ] needs the variable to be inside of “”)

Match
if [[ ${domain} =~ “lalife.net” ]];then
echo “correct”
fi
([ ] doesn’t work with =~)