Thursday, 12 March 2009

"Hello world!" :) Part 2

This is a little update to the post "Hello world!". There us two more languages I'm learning right now, so I decided to add two more Hello World applications.

7. Assembler- PEP72

BR Main
Main: CHARO c#/H/,i
CHARO c#/e/,i
CHARO c#/l/,i
CHARO c#/l/,i
CHARO c#/o/,i
CHARO c#/ /,i
CHARO c#/W/,i
CHARO c#/o/,i
CHARO c#/r/,i
CHARO c#/l/,i
CHARO c#/d/,i
CHARO c#/!/,i


8. JavaScript

<script language="JavaScript">>
document.write("Hello World!");
</script>


It looks quite simple (apart from the assembler, still need a bit of practice in it), but as I said before, writting this kind of programs give the novice programmer lots information about the language structure.

Tuesday, 3 March 2009

Unix shell script 1

The following script finds a given string in the files in given directory. The directory is passed as an argument and it has to be relative path from the users home directory.

#!/bin/csh

if( !( -d ~/$1 ) ) then
echo No directory supplied
exit
endif

echo Enter string:
set w = $<

foreach a ( `ls ~/$1` )
if( !( -d $a ) ) then
set s = `grep -s $w ~/$1/$a | wc -l`

if ( $s>0 ) then
echo $a : $w found
else
echo $a : $w not found
endif
endif
end


As a result we get listing of all files, saying in which the given string has been found and in which has not.