<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4749235378065809125</id><updated>2011-12-06T17:01:46.502-08:00</updated><category term='C++'/><category term='onclick event'/><category term='shell script'/><category term='javascript'/><category term='for loop'/><category term='python'/><category term='loops'/><category term='ajax'/><category term='C'/><category term='Language Translator'/><category term='English to Bisaya Language Translator'/><category term='unix commands'/><category term='English to Cebuano Language Translator'/><category term='Perl'/><category term='Java'/><category term='linux commands'/><category term='Hello World'/><title type='text'>Learning from Examples</title><subtitle type='html'>All I ever wish is that you will gain something from the  examples I wrote in this blog. If you have suggestions, questions, or have a much better way of doing it, please feel free to drop your comments so I may also learn from it and also those who are crawling around this blog. Examples here are mostly about Unix/Linux administration and programming which varies from C, C++, C#, Java, Shell Scripting, PHP to Python and I hope I can post more.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-428909960860269972</id><published>2009-02-27T06:51:00.001-08:00</published><updated>2009-02-27T07:10:45.356-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java Problem 19</title><content type='html'>Here is the solution for Problem number 19. &lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;/*&lt;br /&gt; * 19. Write a Java class called IsPalindrome, which &lt;br /&gt; * defines a main() method that asks the user to enter &lt;br /&gt; * a String s, and displays whether or not s is a &lt;br /&gt; * palindrome. A palindrome is a String which reads the &lt;br /&gt; * same forwards and backwards, such as "laval" or &lt;br /&gt; * "stressed desserts".&lt;br /&gt; * &lt;br /&gt; * Code taken from my previous solution of problem #21&lt;br /&gt; *&lt;br /&gt; * @author obispo &lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.text.*;&lt;br /&gt;class IsPalindrome {&lt;br /&gt; public static void main( String[] args ) {&lt;br /&gt;  String s1, s2;&lt;br /&gt;  int result = 0, len, index1, index2;&lt;br /&gt;&lt;br /&gt;  s1 = JOptionPane.showInputDialog(null, "Enter a string:");&lt;br /&gt;&lt;br /&gt;  for (index1 = 0, index2 = s1.length() - 1; index1 &lt; index2; index1++, index2--) {&lt;br /&gt;   if (s1.charAt(index1) != s1.charAt(index2)) {&lt;br /&gt;    result = -1;&lt;br /&gt;    break;&lt;br /&gt;   } &lt;br /&gt;  }   &lt;br /&gt;  &lt;br /&gt;  if (result == 0) {&lt;br /&gt;   JOptionPane.showMessageDialog(null, "Palindrome !");  &lt;br /&gt;  } else {&lt;br /&gt;   JOptionPane.showMessageDialog(null, "Not Palindrome !");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-428909960860269972?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/428909960860269972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=428909960860269972' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/428909960860269972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/428909960860269972'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2009/02/java-problem-19.html' title='Java Problem 19'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-7056287943875288933</id><published>2009-02-27T06:42:00.000-08:00</published><updated>2009-02-27T06:49:44.663-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java Problem 21</title><content type='html'>The next problem I tried to solved was problem 21. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/*&lt;br /&gt; * 21. Write a Java class called Equals, which defines a &lt;br /&gt; * main() method that asks the user to enter two Strings s1 &lt;br /&gt; * and s2, and displays whether or not s1 and s2 are equal. &lt;br /&gt; * Two Strings are equal if they are of the same length &lt;br /&gt; * and the same characters appear in the same positions. &lt;br /&gt; * You MUST NOT use any of the methods defined in the String &lt;br /&gt; * class other than charAt() and length().&lt;br /&gt; * &lt;br /&gt; * @author obispo&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.text.*;&lt;br /&gt;class Equals {&lt;br /&gt;  public static void main( String[] args ) {&lt;br /&gt;    String s1, s2;&lt;br /&gt;    int result = 0, len, index;&lt;br /&gt;&lt;br /&gt;    s1 = JOptionPane.showInputDialog(null, "Enter first string:");&lt;br /&gt;    s2 = JOptionPane.showInputDialog(null, "Enter second string:");&lt;br /&gt;&lt;br /&gt;    len = s1.length();&lt;br /&gt;    if (len != s2.length()) {&lt;br /&gt;      result = -1;  &lt;br /&gt;    } else {&lt;br /&gt;      for (index = 0; index &lt; len; index++) {&lt;br /&gt;        if (s1.charAt(index) != s2.charAt(index)) {&lt;br /&gt;          result = -1;&lt;br /&gt;        } &lt;br /&gt;      }   &lt;br /&gt;    }&lt;br /&gt;  &lt;br /&gt;    if (result == 0) {&lt;br /&gt;      JOptionPane.showMessageDialog(null, "Equal !\n" + &lt;br /&gt;                         s1 + " == " + s2); &lt;br /&gt;    } else {&lt;br /&gt;      JOptionPane.showMessageDialog(null, "Not Equal !\n" + &lt;br /&gt;                         s1 + " != " + s2); &lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-7056287943875288933?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/7056287943875288933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=7056287943875288933' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/7056287943875288933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/7056287943875288933'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2009/02/java-problem-21.html' title='Java Problem 21'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-3533118759681805554</id><published>2009-02-27T06:34:00.000-08:00</published><updated>2009-02-27T06:40:32.155-08:00</updated><title type='text'>Java Problem 25</title><content type='html'>So I picked the last problem first. And here's my take...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt; * 25.Write a Java class called CountWords, which defines &lt;br /&gt; * a main() method that asks the user to  &lt;br /&gt; * enter a String s, and displays the number of words in s. &lt;br /&gt; * A word is delimited by one or many space &lt;br /&gt; * characters. You MUST NOT not use any of the methods defined in &lt;br /&gt; * the String class other than&lt;br /&gt; * charAt() and length(). In addition, you MUST NOT use the &lt;br /&gt; * StringTokenizer class.&lt;br /&gt; *&lt;br /&gt; * @author obispo&lt;br /&gt; */&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.text.*;&lt;br /&gt;&lt;br /&gt;class CountWords {&lt;br /&gt; public static void main( String[] args ) {&lt;br /&gt;  String s;&lt;br /&gt;  int words = 0, index, len, notspace = 0;&lt;br /&gt;&lt;br /&gt;  s = JOptionPane.showInputDialog(null, "Enter string:");&lt;br /&gt;  s += " ";&lt;br /&gt;  len = s.length();&lt;br /&gt;  for (index = 0; index &lt; len; index++) {&lt;br /&gt;   if (s.charAt(index) != ' ') {&lt;br /&gt;    notspace = 1;&lt;br /&gt;   } else {&lt;br /&gt;    if (notspace == 1) words++;&lt;br /&gt;    notspace = 0;&lt;br /&gt;   }&lt;br /&gt;  }   &lt;br /&gt;  &lt;br /&gt;  JOptionPane.showMessageDialog(null, "Word Count: " + words);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-3533118759681805554?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/3533118759681805554/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=3533118759681805554' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/3533118759681805554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/3533118759681805554'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2009/02/java-problem-25.html' title='Java Problem 25'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-4643898638313145415</id><published>2009-02-27T06:25:00.000-08:00</published><updated>2009-02-27T06:34:11.350-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Java Problems</title><content type='html'>I have found these problems being posted from a certain forum. It has been two years or more since I have coded in Java so I gave it a try and shared my solutions at the forum. I'll just post it here too. Here are the problems...&lt;br /&gt;&lt;br /&gt;Problems:&lt;br /&gt;1. Write a Java class called Factorial which defines a main() method that asks the user to enter a positive integer n and displays the factorial of n. The factorial of an integer n, denoted n!, is defined as n * (n-1) * (n-2) * ... * 1 (but note that 0! is 1).&lt;br /&gt;&lt;br /&gt;2. Write a Java class called Fibonacci which defines a main() method that asks the user to enter a positive integer n, and computes the nth Fibonacci number. The nth Fibonacci number is defined by this formula:&lt;br /&gt;o 0th Fibonacci number: 0&lt;br /&gt;o 1st Fibonnaci number: 1&lt;br /&gt;o nth Fibonacci number (for n &gt;= 2): (n-1)th Fibonacci number + (n-2)th Fibonacci number&lt;br /&gt;3. Write a Java class called CheckPrimality which defines a main() method that asks the user to enter a positive integer n, and displays whether or not n is a prime number. A prime number is an integer which cannot be divided evenly except by 1 and itself.&lt;br /&gt;&lt;br /&gt;4. Write a Java class called Power which defines a main() method that asks the user to enter a double base and a positive integer exponent, and displays base to the power of exponent. You may assume that base and exponent are not both 0. You must write the computation yourself; in other words, you MUST NOT use the Math.pow() method.&lt;br /&gt;&lt;br /&gt;5. Write a Java class called CountDigits which defines a main() method that asks the user to enter a positive integer n, and displays how many digits are in n.&lt;br /&gt;&lt;br /&gt;6. Write a Java class called Contains which defines a main() method that asks the user to enter a String s and a character c, and displays whether or not c occurs in s. You MUST NOT use any methods defined in the String class other than chartAt() and length().&lt;br /&gt;&lt;br /&gt;7. Write a Java class called CountOccurrences which defines a main() method that asks the user to enter a String s and a character c, and displays the number of times c occurs in s.&lt;br /&gt;&lt;br /&gt;8. Write a Java class called CheckDuplicates, which defines a main() method that asks the user to enter a String s, and displays whether or not any character in s occurs more than once.&lt;br /&gt;&lt;br /&gt;9. Write a Java class called MostOftenOccurring which takes a String s and displays the character which occurs most often in String s. If there is a tie, display the character which occurs first in s among those which occur most often.&lt;br /&gt;&lt;br /&gt;10. Write a Java class called ToUpperCase which defines a main() method that asks the user to enter String s and displays a new String which contains exactly the same characters as s in the same order, except that all lower-case letters occurring in s are replaced by their upper-case equivalents in the result String. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;11. Write a Java class called IsAlphabetPermutation, which defines a main() method that asks the user to enter a String s and displays whether or not s is a permutation of the upper case letters in the alphabet.&lt;br /&gt;&lt;br /&gt;12. Write a Java class called OccursHere, which defines a main() method that asks the user to enter two Strings, superString, and subString, as well as a positive integer position, and displays whether or not subString occurs in superString at position position. You may assume that position is within the range [0, superString.length() - 1]. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;13. Write a Java class called OccursAnywhere, which defines a main() method that asks the user to enter two Strings, superString and subString, and displays whether or not subString occurs anywhere in superString. You MUST NOT use any method defined in the String class other than chartAt() and length().&lt;br /&gt;&lt;br /&gt;14. Write a Java class called Substring, which defines a main() method that asks the user to enter a String s, a positive integer position, and a positive integer number, and displays a new String formed by taking the number characters of s starting at position position. If there are less than number characters between position and the end of s, your main() method should display a new String formed by these characters. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;15. Write a Java class called RemoveAll, which defines a main() method that asks the user to enter a String s and a character c, and displays a new String consisting of all the characters in s in the order in which they appear in s, but with all occurrences of c removed. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;16. Write a Java class called NumberConsecutiveOccurrences, which defines a main() that asks the user to enter a String s, a character c, and an integer position, and displays the number of occurrences of c starting at position position in s. For example, if s is "abbbbbaaa", c is 'b', and position is 1, then your main() method will display 5, as there are 5 consecutive occurrences of 'b' starting at position 1. You may assume that position is within the range [0, s.length() - 1]. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;17. Write a Java class called MaxConsecutiveOccurrences, which defines a main() method that asks the user to enter a String s and a character c, and displays the position in s at which the longest series of consecutive occurrences of c occurs. If there is a tie between two positions, you should return the lowest position. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;18. Write a Java class called Reverse, which defines a main() method that asks the user to enter a String s, and displays a new String consisting of the characters in s in the reverse order. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;19. Write a Java class called IsPalindrome, which defines a main() method that asks the user to enter a String s, and displays whether or not s is a palindrome. A palindrome is a String which reads the same forwards and backwards, such as "laval" or "stressed desserts".&lt;br /&gt;&lt;br /&gt;20. Write a Java class called KillWhiteSpace, which defines a main() method that asks the user to enter a String s, and displays a new String consisting of all the characters in s, but with the leading and trailing white space removed. In addition, every sequence of spaces within the String is reduced to one space only. You MUST NOT use any methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;21. Write a Java class called Equals, which defines a main() method that asks the user to enter two Strings s1 and s2, and displays whether or not s1 and s2 are equal. Two Strings are equal if they are of the same length and the same characters appear in the same positions. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;22. Write a Java class called DestroyAllOccurrences, which defines a main() method that asks the user to enter two Strings superString and subString, and displays a new String consisting of all characters in superString with all occurrences of subString deleted. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;23. Write a Java class called SubSet, which defines a main() method that asks the user to enter two Strings superString and subString, and displays whether or not all the characters of subString occur anywhere in superString. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;24. Write a Java class called AppearInOrder(), which defines a main() method that asks the user to enter two Strings subString and superString, and displays whether or not all the characters of subString appear in order in superString. You MUST NOT use any of the methods defined in the String class other than charAt() and length().&lt;br /&gt;&lt;br /&gt;25. Write a Java class called CountWords, which defines a main() method that asks the user to enter a String s, and displays the number of words in s. A word is delimited by one or many space characters. You MUST NOT not use any of the methods defined in the String class other than charAt() and length(). In addition, you MUST NOT use the StringTokenizer class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-4643898638313145415?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/4643898638313145415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=4643898638313145415' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4643898638313145415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4643898638313145415'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2009/02/java-problems.html' title='Java Problems'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-6432311146509471467</id><published>2008-11-10T17:30:00.000-08:00</published><updated>2008-11-10T17:43:26.466-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><title type='text'>Perl: Rounding off Decimal Digits</title><content type='html'>&lt;pre&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;# Filename: kb_converter.pl&lt;br /&gt;# Description: Convert values from Bytes to KiloBytes&lt;br /&gt;use strict;&lt;br /&gt;&lt;br /&gt;my $val;&lt;br /&gt;my $argc = @ARGV;&lt;br /&gt;if($argc == 1) {&lt;br /&gt;    $val = shift;&lt;br /&gt;} else {&lt;br /&gt;    $val = 12345;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# 1KB = 1024Bytes&lt;br /&gt;my $val_kb = $val / 1024;&lt;br /&gt;my $val_kb_rounded = sprintf("%.2f", $val / 1024);&lt;br /&gt;print "Not Rounded Answer:\n$val Bytes = $val_kb KB\n";&lt;br /&gt;print "Rounded Answer:\n$val Bytes = $val_kb_rounded KB\n";&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-6432311146509471467?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/6432311146509471467/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=6432311146509471467' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6432311146509471467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6432311146509471467'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/11/perl-rounding-off-decimal-digits.html' title='Perl: Rounding off Decimal Digits'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-949992224352967981</id><published>2008-08-13T01:33:00.000-07:00</published><updated>2008-08-13T02:57:26.585-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux commands'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='unix commands'/><title type='text'>The Unix/Linux 'search' command</title><content type='html'>&lt;h3&gt;How to find files in Linux or Unix using 'find'&lt;/h3&gt;&lt;br /&gt;The 'find' command is very effective in searching for files in my Unix or Linux box. Here's how you do it:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# find &amp;lt;path&amp;gt; -name "&amp;lt;filename&amp;gt;" -print&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Example 1: Let us search for the file 'sshd' from the root('/') directory. &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# find / -name "sshd" -print&lt;br /&gt;./usr/sbin/sshd&lt;br /&gt;./usr/src/etc/pam.d/sshd&lt;br /&gt;./usr/src/etc/rc.d/sshd&lt;br /&gt;./usr/src/secure/usr.sbin/sshd&lt;br /&gt;./etc/pam.d/sshd&lt;br /&gt;./etc/rc.d/sshd&lt;br /&gt;#&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So, there it is, the 'sshd' file can be found from those six different locations.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Searching a File containing a particular text string in Unix or Linux&lt;/h3&gt;&lt;br /&gt;Again, I use the 'find' command for this. The syntax is as follow:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# find &amp;lt;path&amp;gt; -exec grep "&amp;lt;search_string&amp;gt;" '{}' \; -print&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Example 2: Let us search for files that contains the string "dhclient_start" from the etc('/etc') directory. &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# find /etc -exec grep "dhclient_start" '{}' \; -print&lt;br /&gt;start_cmd="dhclient_start"&lt;br /&gt;dhclient_start()&lt;br /&gt;/etc/rc.d/dhclient&lt;br /&gt;#&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The output tells us that it has only found one file that contains the string we were looking for. It can be found inside the file '/etc/rc.d/dhclient'.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;This is my simplified 'search' command&lt;/h3&gt;&lt;br /&gt;I tried to simplify the find command by creating a shell script which will accept only three parameters:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# search &amp;lt;search_path&amp;gt; &amp;lt;search_type&amp;gt; &amp;lt;search_string&amp;gt;&lt;br /&gt;&lt;br /&gt;Where:&lt;br /&gt;search_path:&lt;br /&gt;    ex. /usr/local&lt;br /&gt;search_type:&lt;br /&gt;    file - search for a file/directory&lt;br /&gt;    content - search for a file content&lt;br /&gt;search_string:&lt;br /&gt;    - the filename or the file content you want to search&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Example 3: Let us search for the file 'sshd' from the root('/') directory. &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# search / file "sshd"&lt;br /&gt;./usr/sbin/sshd&lt;br /&gt;./usr/src/etc/pam.d/sshd&lt;br /&gt;./usr/src/etc/rc.d/sshd&lt;br /&gt;./usr/src/secure/usr.sbin/sshd&lt;br /&gt;./etc/pam.d/sshd&lt;br /&gt;./etc/rc.d/sshd&lt;br /&gt;#&lt;br /&gt;&lt;code&gt;&lt;/pre&gt;&lt;br /&gt;The output is the same with Example 1 but as you notice we only have three parameters in our command which makes is simpler to understand. &lt;br /&gt;&lt;br /&gt;Example 4: Let us search for files that contains the string "dhclient_start" from the etc('/etc') directory. &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;# search /etc content "dhclient_start"&lt;br /&gt;start_cmd="dhclient_start"&lt;br /&gt;dhclient_start()&lt;br /&gt;/etc/rc.d/dhclient&lt;br /&gt;#&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The output is also the same with Example 2 and again the command only take three parameters.&lt;br /&gt;&lt;br /&gt;Here is the script, you can copy and paste this script and save it to a file named 'search'. After saving the file, change the permission of the file to '+x' and copy it to '/usr/local/bin'. &lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# Filename: search&lt;br /&gt;# Description: A simplified find command&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;searchPath=""&lt;br /&gt;searchType=""&lt;br /&gt;searchString=""&lt;br /&gt;findcmd="/usr/bin/find"&lt;br /&gt;scriptUsage="&lt;br /&gt;Usage:&lt;br /&gt;${0} &amp;lt;search_path&amp;gt; &amp;lt;search_type&amp;gt; &amp;lt;search_string&amp;gt;&lt;br /&gt;search_path:&lt;br /&gt;    ex. /usr/local&lt;br /&gt;search_type:&lt;br /&gt;    file - search for a file/directory&lt;br /&gt;    content - search for a file content&lt;br /&gt;search_string:&lt;br /&gt;    - the filename or the file content you want to search&lt;br /&gt;"&lt;br /&gt;&lt;br /&gt;# Script Usage&lt;br /&gt;display_usage()&lt;br /&gt;{&lt;br /&gt;    echo "${scriptUsage}"&lt;br /&gt;    exit 1&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if [ "${1}" = "" ]; then&lt;br /&gt;    display_usage&lt;br /&gt;elif [ "${2}" = "" ]; then&lt;br /&gt;    display_usage&lt;br /&gt;elif [ "${3}" = "" ]; then&lt;br /&gt;    display_usage&lt;br /&gt;else&lt;br /&gt;    searchPath=${1}&lt;br /&gt;    searchType=${2}&lt;br /&gt;    searchString=${3}&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;case "${searchType}" in&lt;br /&gt;file)&lt;br /&gt;    ${findcmd} ${searchPath} -name "${searchString}" -print&lt;br /&gt;;;&lt;br /&gt;content)&lt;br /&gt;    ${findcmd} ${searchPath} -exec grep "${searchString}" '{}' \; -print&lt;br /&gt;;;&lt;br /&gt;*)&lt;br /&gt;    display_usage&lt;br /&gt;;;&lt;br /&gt;esac&lt;br /&gt;&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Enjoy!&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-949992224352967981?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/949992224352967981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=949992224352967981' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/949992224352967981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/949992224352967981'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/08/unixlinux-search-command.html' title='The Unix/Linux &apos;search&apos; command'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-6337650605857233755</id><published>2008-07-24T17:21:00.000-07:00</published><updated>2008-08-13T01:08:56.398-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='English to Bisaya Language Translator'/><category scheme='http://www.blogger.com/atom/ns#' term='Language Translator'/><category scheme='http://www.blogger.com/atom/ns#' term='English to Cebuano Language Translator'/><title type='text'>English to Bisaya Language Translator</title><content type='html'>Hmmm... I have successfully created an English to Bisaya Language Translator about 3 years ago, as a project in my Natural Language Processing (NLP) subject and I developed it using Visual Basic 6. Luckily last weekend, as I tried to clear some trash in my room, I found the Object Schema documentation of my project! &lt;br /&gt;&lt;br /&gt;This leads me to an idea of creating an online English to Bisaya Language Translator project using PHP... Do you think this is a great idea? I have seen that the number of tourist people here in Cebu and in some parts of the Philippines is growing and I think this online language translator can help them learn about our Bisayan or Cebuano language.&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-6337650605857233755?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/6337650605857233755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=6337650605857233755' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6337650605857233755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6337650605857233755'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/07/english-to-bisaya-language-translator.html' title='English to Bisaya Language Translator'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-1345704784499213508</id><published>2008-07-23T17:35:00.000-07:00</published><updated>2008-08-13T01:08:45.321-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='onclick event'/><category scheme='http://www.blogger.com/atom/ns#' term='ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Hello World'/><title type='text'>JavaScript onClick Event</title><content type='html'>&lt;p&gt;&lt;br /&gt;This is another "Hello World" example using JavaScript. The example below is a html script that is embedded with a javascript that will display a message in a messagebox whenever the button is clicked.&lt;br /&gt;&lt;br /&gt;Your javascript must be placed inside the &amp;lt;head&amp;gt &amp;lt;/head&amp;gt; section of your html code. The javascript code must also be enclosed with the tag &amp;lt;script&amp;gt; &amp;lt;/script&amp;gt;. Inside the &amp;lt;script&amp;gt; tag, you need to set the language property to "javascript". &lt;br /&gt;&lt;br /&gt;The script is simple,  we declare a new function called greet() and when this function is called, it will call a javascript built-in function called alert(). The alert function will pop-up a messagebox displaying the string "Hello! How are you today?". &lt;br /&gt;&lt;br /&gt;Now that we have our javascript, we need to call the greet() function whenever a certain event is triggered. In this example, we added a button in our html code and set the onClick event of this button to call the function greet().&lt;br /&gt;&lt;br /&gt;You try clicking the "Hello World" button below to see the output of this script.&lt;br /&gt;&lt;/p&gt; &lt;br /&gt;&lt;b&gt;The Script&lt;/b&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Yet another Hello World&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;script language="javascript"&amp;gt;&lt;br /&gt;   function greet()&lt;br /&gt;   {&lt;br /&gt;       alert("Hello! How are you today?");&lt;br /&gt;   }&lt;br /&gt;&amp;lt;/script&amp;gt&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form name="Form1"&amp;gt;&lt;br /&gt;    &amp;lt;input type="button"&lt;br /&gt;            name="btnGreeter" &lt;br /&gt;            value="Hello World" &lt;br /&gt;            onclick="greet()" /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Output&lt;/b&gt;&lt;br /&gt;&lt;form name="Form1"&gt;&lt;br /&gt;  &lt;input name="btnGreeter" value="Hello World" onclick="greet()" type="button"&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-1345704784499213508?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/1345704784499213508/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=1345704784499213508' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/1345704784499213508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/1345704784499213508'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/07/var-browsername-navigator.html' title='JavaScript onClick Event'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-4146855699951835284</id><published>2008-05-08T19:20:00.000-07:00</published><updated>2008-08-13T01:08:30.936-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Accepting Inputs in Python</title><content type='html'>I want to learn how to get or accept inputs in python. I want to start from the very basic. In C, there are several functions you can choose from, the very basic is scanf(). In python, there is this raw_input() function. The raw_input([prompt])  function will first display what is placed in [prompt] then wait for keyboard input(s) and return the input as a string.&lt;br /&gt;&lt;br /&gt;Now, lets try this example:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# Filename: greeter.py&lt;br /&gt;# Description: A program that ask for a name and greet hello.&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# Ask for a name.&lt;br /&gt;iname = raw_input("What's your name? ")&lt;br /&gt;# Be courteous&lt;br /&gt;print "Oh, hello " + iname + "! Glad to meet you!"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here is the output of our greeter.py code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# ./greeter.py&lt;br /&gt;What's your name? Juan&lt;br /&gt;Oh, hello Juan! Glad to meet you!&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;We have to take note that raw_input() will return the input as a string. Let us take a look at our second example. Suppose I want to ask two numbers and display the sum of those numbers? Let us try:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# Filename: simplemath.py&lt;br /&gt;# Description: A program that takes two numbers and display the sum&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# Ask for the first number&lt;br /&gt;num1 = raw_input("Enter first number: ")&lt;br /&gt;# Ask for the second number&lt;br /&gt;num2 = raw_input("Enter second number: ")&lt;br /&gt;# Alright, let's display the sum&lt;br /&gt;print "The sum of ", num1, " and ", num2, " is ", (num1 + num2)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I wanna see the output now!&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# chmod +x simplemath1.py&lt;br /&gt;# ./simplemath1.py&lt;br /&gt;Enter first number: 5&lt;br /&gt;Enter second number: 3&lt;br /&gt;The sum of  5  and  3  is  53&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Oh, I don't think the answer is correct. What happened? As I have said, raw_input() will return a string, so, when we type 5 and 3, num1 and num2 contains the string "5" and "3" respectively. What about (num1 + num2)? Would it not automatically convert num1 and num2 into a numerical value then add? Well, from the output of the program, it didn't add num1 and num2 but instead, it concatenate the two strings "5" + "3" equals "53"!&lt;br /&gt;&lt;br /&gt;You will notice that in our first example (greeter.py), we print our message like this: "Oh, hello " + "Juan" + "! Glad to meet you!". The "+" operator will be used to concatenate two strings if our operands are strings but it can also be used to add two values if our operands are numeric values.&lt;br /&gt;&lt;br /&gt;In order to get the desired result, I used the function float() in order to convert the input "5" into a numeric value 5.0 and the input "3" into a numeric value 3.0. You can also try to use other numeric conversion functions like int() and long().&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# Filename: simplemath.py&lt;br /&gt;# Description: A program that takes two numbers and display the sum&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# Ask for the first number&lt;br /&gt;num1 = float(raw_input("Enter first number: "))&lt;br /&gt;# Ask for the second number&lt;br /&gt;num2 = float(raw_input("Enter second number: "))&lt;br /&gt;# Alright, let's display the sum&lt;br /&gt;print "The sum of ", num1, " and ", num2, " is ", (num1 + num2)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Let's see the output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# ./simplemath.py&lt;br /&gt;Enter first number: 5&lt;br /&gt;Enter second number: 3&lt;br /&gt;The sum of  5.0  and  3.0  is  8.0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Whew! At last, the output seems to be correct now. What I want to learn next is how to trap errors in python, try to explore the program and you will see why.&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-4146855699951835284?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/4146855699951835284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=4146855699951835284' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4146855699951835284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4146855699951835284'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/05/accepting-inputs-in-python.html' title='Accepting Inputs in Python'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-6907790283999315119</id><published>2008-05-06T17:13:00.000-07:00</published><updated>2008-08-13T01:08:16.468-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='for loop'/><category scheme='http://www.blogger.com/atom/ns#' term='linux commands'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='unix commands'/><title type='text'>Transferring Files using Shell Script</title><content type='html'>I have a directory where all my test codes are in there. I have test codes for C, shell scripts, perl and etc inside this directory. I realized that I could organize it further if I'll create a directory for c source codes, shell script source codes and etc. If I'll do the task manually, it will be a repetitive task. So I wrote a shell script to do the task for me.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# Filename: organize.sh&lt;br /&gt;# Description: A simple program that will transfer&lt;br /&gt;#              selected files to a certain directory&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# create a directory for c files&lt;br /&gt;mkdir cfiles&lt;br /&gt;&lt;br /&gt;# create a directory for sh files&lt;br /&gt;mkdir shfiles&lt;br /&gt;&lt;br /&gt;# transfer all c source codes to cfiles directory&lt;br /&gt;for f in `ls *.c`&lt;br /&gt;do&lt;br /&gt;  mv ${f} ./cfiles&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;# transfer all shell scripts to shfiles directory&lt;br /&gt;for f in `ls *.sh`&lt;br /&gt;do&lt;br /&gt;  mv ${f} ./shfiles&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Okay, here's how I came up with the program. If I'll execute the command 'ls *.c' at the console, it will display all the files that ends with '.c' right? So what I did was to get these files that ends with '.c' one by one and place it in a variable called 'f' then move it to my cfiles directory. The Unix command to move a file to another directory is 'mv'.&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-6907790283999315119?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/6907790283999315119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=6907790283999315119' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6907790283999315119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6907790283999315119'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/05/transferring-files-using-shell-script.html' title='Transferring Files using Shell Script'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-246399118786141811</id><published>2008-05-02T06:44:00.000-07:00</published><updated>2008-08-13T01:08:04.597-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='loops'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Counting Numbers in Shell Scripts</title><content type='html'>Scripts are very useful especially in automating repetitive task for system administration. Let me share to you a very simple shell script that will display numbers from 1 to 10 using while loop.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# Filename: count.sh&lt;br /&gt;# Description: Display numbers 1 to 10 using while loop&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# initialize a variable&lt;br /&gt;i=1&lt;br /&gt;&lt;br /&gt;# do the loop&lt;br /&gt;while [ ${i} -le 10 ]&lt;br /&gt;do&lt;br /&gt;    # you may place your repetitive task here&lt;br /&gt;    echo "count: ${i}"&lt;br /&gt;    i=`expr ${i} + 1`&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;code&gt;# ./count.sh&lt;br /&gt;count: 1&lt;br /&gt;count: 2&lt;br /&gt;count: 3&lt;br /&gt;count: 4&lt;br /&gt;count: 5&lt;br /&gt;count: 6&lt;br /&gt;count: 7&lt;br /&gt;count: 8&lt;br /&gt;count: 9&lt;br /&gt;count: 10&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You're probably wondering whats the use of printing numbers 1 to 10 in the screen? I know how to that even when my eyes are closed. Well, all I can say is that you will need it someday when you grow up. :)&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-246399118786141811?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/246399118786141811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=246399118786141811' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/246399118786141811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/246399118786141811'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/05/counting-numbers-in-shell-scripts.html' title='Counting Numbers in Shell Scripts'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-7747207079365105877</id><published>2008-05-01T21:47:00.000-07:00</published><updated>2008-08-13T01:07:49.339-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Variables in Python 2</title><content type='html'>So, where am I now in my study of python? Ah! in my last post, I assigned numeric values to variables a, b and c. This time, I want to have a variable that contains a string, how am I going to do that? &lt;br /&gt;&lt;br /&gt;Try this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# Filename : stringvar.py&lt;br /&gt;# Description : A simple example that shows how to assign a string to a variable&lt;br /&gt;# Author : Obispo&lt;br /&gt;&lt;br /&gt;str="Hello World!"&lt;br /&gt;print "str = ", str&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Output: &lt;br /&gt;&lt;code&gt;&lt;br /&gt;# ./stringvar.py&lt;br /&gt;str =  Hello World!&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;That's it! The code is so straight forward. Luckily python is not like any other programming language wherein you need to define the data type of your variable first before assigning value into it.&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-7747207079365105877?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/7747207079365105877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=7747207079365105877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/7747207079365105877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/7747207079365105877'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/05/variables-in-python.html' title='Variables in Python 2'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-6746902880636181515</id><published>2008-04-30T19:47:00.000-07:00</published><updated>2008-08-13T01:07:36.254-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Variables in Python 1</title><content type='html'>Honestly, I got so excited learning Python after I discovered how to write the "Hello World!" program in Python. From my "Hello World!" program, I learned how to place comments in my program, in the beginning of your comment, you just got to place a sharp(#) to denote that the line is not part of the code, its only a comment. &lt;br /&gt;&lt;br /&gt;Displaying a string in python was never hard at all, all I did was to call the instruction 'print' then preceded with the string I want to display which is of course the "Hello World!" string enclosed with a double-quote.&lt;br /&gt;&lt;br /&gt;But wait! Is the first line of my code also a comment? I didn't know that writing a blog would make me feel like crazy. I got to answer my own questions! hehehe! &lt;br /&gt;&lt;br /&gt;Here's the first line of the hello.py code:&lt;br /&gt;&lt;code&gt;#!/usr/bin/env python&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;That's the first line I was referring to. Hmmm... It looks like its also a comment right? This first line is very important in python programming. Just like Shell programming or Perl programming, this first line tells the my FreeBSD or the Unix box that the hello.py is to be executed with the python interpreter. &lt;br /&gt;&lt;br /&gt;So much for the hello.py. In programming, it is very important that you know how to use variables. So this is my first program in python that shows you how to use variables:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# Filename: variables.py&lt;br /&gt;# Description: A simple program that shows how to use variables in python&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;# Lets declare a variable called a and assign it with a value equal to 1&lt;br /&gt;a = 1&lt;br /&gt;&lt;br /&gt;# Lets declare a variable called b and assign it with a value equal to 2&lt;br /&gt;b = 2&lt;br /&gt;&lt;br /&gt;# Lets declare a variable called c and assign it with a value equal to 3&lt;br /&gt;c = 3&lt;br /&gt;&lt;br /&gt;print "Variable a is ", a&lt;br /&gt;print "Variable b is ", b&lt;br /&gt;print "Variable c is ", c&lt;br /&gt;print "Sum of a + b + c is ", a + b + c&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Again, I used vi editor to type this code and saved it with a filename variables.py. I also made the program executable using the command 'chmod +x variables.py'. Excited to see the output of this code? Here's the output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# ./variables.py&lt;br /&gt;Variable a is  1&lt;br /&gt;Variable b is  2&lt;br /&gt;Variable c is  3&lt;br /&gt;Sum of a + b + c is  6&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;That's it! Waaa... Those variables contains only numbers, how about having a variable that contains strings? &lt;br /&gt;&lt;br /&gt;Hmm... I wanna learn that one too, but I've got no time to study and write anymore, it 11:21AM now and I have a lunch date with my wife. Got to go now, til next time...&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-6746902880636181515?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/6746902880636181515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=6746902880636181515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6746902880636181515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/6746902880636181515'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/04/1-2-3-in-python.html' title='Variables in Python 1'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4749235378065809125.post-4766655112637867890</id><published>2008-04-30T19:18:00.000-07:00</published><updated>2008-08-13T01:07:21.809-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='Hello World'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Hello World in Python</title><content type='html'>I'm trying to study programming or scripting with Python and I remember when I first learned programming in C, I started with writing a "Hello World!" program. &lt;br /&gt;&lt;br /&gt;Since this is my first time in python too, I want to convert my "Hello World!" program in C into Python and this is how it looks like:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;# This is a comment in python&lt;br /&gt;# Filename: hello.py&lt;br /&gt;# Description: This program will display the very famous "Hello World!" in python&lt;br /&gt;# Author: Obispo&lt;br /&gt;&lt;br /&gt;print "Hello World!"&lt;br /&gt;&lt;br /&gt;# The program ends here&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I installed my python interpreter at my FreeBSD box and used the vi editor to write this code. I named the program "hello.py" and after saving it, I make it executable by changing the user permission of the file to executable. I used the command:&lt;br /&gt;&lt;code&gt;# chmod +x hello.py&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now that its executable, I got very excited to see the output. And so I run the program like this:&lt;br /&gt;&lt;code&gt;# ./hellopython.py&lt;br /&gt;Hello World!&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The "Hello World!" message did appear! Wow!&lt;br /&gt;&lt;a href="http://digg.com/submit?phase=2&amp;url=http://learningfromexamples.blogspot.com/2008/04/hello-world-in-python.html"&gt;Digg&lt;/a&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post BEGIN --&gt;&lt;br /&gt;&lt;div&gt;&lt;script type='text/javascript'&gt;addthis_url='&lt;data:post.url/&gt;'; addthis_title='&lt;data:post.title/&gt;'; addthis_pub='rslaranjo';&lt;/script&gt;&lt;script src='http://s7.addthis.com/js/addthis_widget.php?v=12' type='text/javascript'&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- AddThis Button for Post END --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4749235378065809125-4766655112637867890?l=learningfromexamples.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learningfromexamples.blogspot.com/feeds/4766655112637867890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4749235378065809125&amp;postID=4766655112637867890' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4766655112637867890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4749235378065809125/posts/default/4766655112637867890'/><link rel='alternate' type='text/html' href='http://learningfromexamples.blogspot.com/2008/04/hello-world-in-python.html' title='Hello World in Python'/><author><name>obispo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
