Scripting Problem (revisi 121003-r04KI)

Return to Lab 03

  • 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 TOKEN with your token.
    $ vi kodesoal

    # Nama NPM is doing scripting problem. As if I don't have enough problems already :/
    # ZCZC TOKEN
    
    # Get the content of a file and put it in a variable.
    teks=`cat $1`
    echo "$teks" 
    
    # Find how many times 10110 occurs.
    
    # Find how many times 11100 occurs.
    
    # Find how many times 10101.
    
    # Print character 48 - 52.
    
    # Print character 36 - 32 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. 10110
    2. 11100
    3. 10101
  3. Print 5 characters in the file start from character 48.
  4. Print 5 characters start from 36 from behind (character 36 - 32 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_10110
    times_11100
    times_10101
    character 48 - 52
    character 36 - 32 from behind

    Example of the answer:
    1202000818
    384
    24
    192
    01011
    10101
  • This marks the end of scripting problem.

Return to Lab 03
Return to Wiki