Scripting Problem (revision 150916-r01)

Return to Lab 01

  • Execute gentext program
    $ gentext NPM tanya.txt

    Change NPM with your student ID, for example:
    $ gentext 1202000818 tanya.txt
  • In your directory there will be a file named tanya.txt. Open the file in vi.
    $ vi tanya.txt
  • Looks like there are only 1 and 0 inside. Pretty harmless.
    101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100101101001011010010110100111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111111001111110011111100111101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000101011000
    
  • Create a file named kodesoal with below content. Change Nama with your name, NPM with your student ID, and KELAS with your kelas.
    $ vi kodesoal

    # Nama NPM is doing scripting problem. As if I don't have enough problems already :/
    # ZCZC NPM KELAS
    
    # Get the content of a file and put it in a variable.
    teks=`cat $1`
    echo "$teks" 
    
    # Find how many times 10101 occurs.
    
    # Print character 23 - 31.
    
    # Print character 30 - 27 from behind.
  • Change the permission of kodesoal to 755. Execute the script using tanya.txt as the input.
    $ chmod 755 kodesoal
    $ ./kodesoal tanya.txt

    Just like in the tutorial, this script put the content of tanya.txt to teks variable and print the variable.
  • We will modify kodesoal. Using the previously acquired knowledge, modify kodesoal script to serve these requests:
  1. First we will change the script so that it will print your NPM rather than the content of tanya.txt. Change NPM with your student ID.
    vi kodesoal

    teks=`cat $1`
    echo "NPM"
  2. Inside tanya.txt, find out how many times these combinations are printed:
    1. 10101
  3. Print characters 23 to 31.
  4. Print characters 30 to 27 from behind. For example, in a string aaBBccDDyyXX, character 6 - 3 from behind is DDyy. Hint: combine the script to find length of a string with the script to find substring from certain position that you've done before. Do each problems under the comment sections that's been provided.
  5. Execute your script and save the output to a file named jawab.txt. The format of your answer should be as follows:
    ./kodesoal tanya.txt > jawab.txt

    NPM
    times_10101
    character 23 - 31
    character 30 - 27 from behind

    Example of the answer:
    1202000818
    192
    010110100
    1010
  • This marks the end of scripting problem.

Return to Lab 01
Return to Wiki