Jeng-sheng Yeh

Here I compile several useful scripts together.

Below The most important thing for shell script is: How to use the flow control? ex. if, for, while, readfile, etc
for perl, please `info perlvar`, `info perlfunc`, `info perlsyn`
for bash, please `man bash`/`info bash', and Loop
for name [ in word] ; do list ; done
for (( expr1 ; expr2; expr3 )) ; do list ; done
if list; then list; [elif list; then list; ] ... [else list; ] fi

Below is a perl script to delete some Emanuel virus from mail folder file. 2,6,2001 jsyeh, with the help from joller

@line_from = (`grep -nia '^from ' $ARGV[0]`);
@line_from = map { (/^(\d+)/)[0]} @line_from;
@line_att = (`grep -nia 'filename="Emanuel\\.exe"' $ARGV[0]`);
@line_att = map { (/^(\d+)/)[0]} @line_att;


#@line_from = (1, 2, 3, 4, 5, 7, 8, 9);
#@line_att = ( 6, 10);

foreach $i (@line_att)
    for(;$from<@line_from; $from++)
        last if $line_from[$from]>$i;
    push @sick, $line_from[$from-1];

push @sick, -1;

$flag = 0;

    if($. == $sick[0])
        $flag = 1;
        shift @sick;
    if($flag==1 and /^from /i)
        $flag = 0;

    print if $flag==0;

Below script could move filename to lower case. (6,16,2003)
for filename in $(ls |grep [A-Z]); do mv $filename $(echo $filename |tr [:upper:] [:lower:]); done
I learned above script from:
[buug] lowercase coversion of filenames (http://www.weak.org/pipermail/buug/2002-August/001176.html)

or another version:

for i in *; do
        mv $i `echo $i | tr \[A-Z] \[a-z]`

Here is a very useful script for finding files when writing program:
find . -name \*.h -exec grep -l the_string {} \;
I always take this line as a gift to every newbie I met if I believe he has the potential to become a UNIX Power User ^^;; (since 1997)

How to delete temp files in Windows2000?
There is a simple script to do this: (in dos commend.exe)

(this will be very useful if the Windows2000 is shared by several users who didn't set their InternetExplorer well on Temp Internet File size) (Another important skill is to find "How to set the size batchly)

cd c:\docume~1\
for /d %i in (*) do dir "%i/Local Settings"
(runas, c:\temp, docume~1\*\LocalSettings\Temp, Temporary Internet Files)
(del /s/q temp, etc
for %i in (  --- I forget the detail ^^;; 
for /d %%x in (*) do rd /q /s "%%x\Local Settings\Temp"
for /d %%x in (*) do rd /q /s "%%x\Local Settings\Temporary Internet Files"
put above 2 lines in c:\docme~1\clean.bat and run it if your c: is run out of disk
Below is useful bash HOWTO:
or search "if list"
if list; then list; [ elif list; then list; ] ... [ else list; ] fi
if [[ -f $1.pdb ]] #Be careful that the [[ (space) ... (space) ]]
then echo ;