├── LICENSE ├── README.md ├── assignment_0 ├── README.md ├── evaluation_file.sh ├── hello.txt └── script.sh ├── assignment_1 ├── README.md └── evaluation_file.sh ├── assignment_10 ├── README.md └── evaluation_file.sh ├── assignment_2 ├── README.md └── evaluation_file.sh ├── assignment_3 ├── README.md └── evaluation_file.sh ├── assignment_4 ├── README.md └── evaluation_file.sh ├── assignment_5 ├── README.md └── evaluation_file.sh ├── assignment_6 ├── README.md └── evaluation_file.sh ├── assignment_7 ├── README.md └── evaluation_file.sh ├── assignment_8 ├── README.md └── evaluation_file.sh ├── assignment_9 ├── README.md ├── evaluation_file.sh └── info.txt ├── practice_2.1 ├── README.md ├── evaluation_file.sh └── init.sh ├── practice_2.2 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_2.3 ├── README.md └── evaluation_file.sh ├── practice_3.1 ├── README.md ├── ans.txt ├── evaluation_file.sh └── init.sh ├── practice_3.2 ├── README.md ├── ans.txt └── evaluation_file.sh ├── practice_4.1 ├── README.md ├── evaluation_file.sh ├── init.sh ├── lsinfo.txt └── output ├── practice_4.10 ├── 1.cpp ├── 10.cp ├── 2.cpp ├── 3.cpp ├── 4.cpp ├── 5.cpp ├── 6.cpp ├── 7.cpp ├── 8.cpp ├── 9.cpp ├── README.md ├── evaluation_file.sh ├── init.sh └── output ├── practice_4.2 ├── README.md ├── evaluation_file.sh ├── init.sh ├── lsinfo.txt └── output ├── practice_4.3 ├── README.md ├── evaluation_file.sh ├── init.sh └── twocities.txt ├── practice_4.4 ├── README.md ├── evaluation_file.sh ├── init.sh ├── output └── twocities.txt ├── practice_4.5 ├── README.md ├── evaluation_file.sh ├── file.txt ├── init.sh └── output ├── practice_4.6 ├── README.md ├── evaluation_file.sh ├── init.sh ├── output └── twocities.txt ├── practice_4.7 ├── README.md ├── evaluation_file.sh ├── file.txt ├── init.sh └── output ├── practice_4.8 ├── README.md ├── evaluation_file.sh ├── file.txt ├── init.sh └── output ├── practice_4.9 ├── 1.cpp ├── 10.cp ├── 2.cpp ├── 3.cpp ├── 4.cpp ├── 5.cpp ├── 6.cpp ├── 7.cpp ├── 8.cpp ├── 9.cpp ├── README.md ├── evaluation_file.sh ├── init.sh └── output ├── practice_5.1 ├── README.md ├── evaluation_file.sh └── expected_output.txt ├── practice_5.10 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── getop │ └── input └── test_case_2 │ ├── getop │ └── input ├── practice_5.11 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ └── input └── test_case_2 │ └── input ├── practice_5.12 ├── README.md └── evaluation_file.sh ├── practice_5.2 ├── README.md ├── evaluation_file.sh └── init.sh ├── practice_5.3 ├── README.md ├── evaluation_file.sh └── init.sh ├── practice_5.4 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_5.5 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_5.6 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_5.7 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output ├── test_case_3 │ ├── input │ └── output └── test_case_4 │ ├── input │ └── output ├── practice_5.8 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output └── test_case_2 │ ├── input │ └── output ├── practice_5.9 ├── README.md ├── ans.txt └── evaluation_file.sh ├── practice_7.1a ├── README.md └── evaluation_file.sh ├── practice_7.1b ├── README.md └── evaluation_file.sh ├── practice_7.1c ├── README.md └── evaluation_file.sh ├── practice_7.2 ├── README.md └── evaluation_file.sh ├── practice_7.3 ├── README.md └── evaluation_file.sh ├── practice_7.4 ├── README.md └── evaluation_file.sh ├── practice_7.5 ├── README.md └── evaluation_file.sh ├── practice_7.6 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ └── output ├── test_case_2 │ └── output └── test_case_3 │ └── output ├── practice_7.7 ├── README.md └── evaluation_file.sh ├── practice_7.8 ├── README.md ├── evaluation_file.sh └── test_case_1 │ ├── input │ └── output ├── practice_7.9 ├── README.md ├── evaluation_file.sh └── test_case_1 │ ├── input │ └── output ├── practice_8.1 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_8.2 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output ├── test_case_2 │ ├── input │ └── output └── test_case_3 │ ├── input │ └── output ├── practice_8.3 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ └── input ├── test_case_2 │ └── input └── test_case_3 │ └── input ├── practice_8.4 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── input │ └── output └── test_case_2 │ ├── input │ └── output ├── practice_8.5 ├── README.md ├── evaluation_file.sh └── test_case_1 │ ├── input │ └── output ├── practice_9.1 ├── README.md └── evaluation_file.sh ├── practice_9.2 ├── README.md ├── evaluation_file.sh └── test_case_1 │ ├── input │ └── output ├── practice_9.3 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ ├── file1 │ ├── file2 │ └── output └── test_case_2 │ ├── file1 │ ├── file2 │ └── output ├── practice_9.4 ├── README.md ├── evaluation_file.sh ├── test_case_1 │ └── input ├── test_case_2 │ └── input └── test_case_3 │ └── input └── practice_9.5 ├── README.md ├── evaluation_file.sh ├── test_case_1 ├── input └── output └── test_case_2 ├── input └── output /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to the System Commands VM 2 | 3 | ## Get started with the course VM 4 | 5 | - Your VM assignments can be found at the directory `/opt/se2001//` 6 | 7 | - Your solution has to be present in directory `~/se2001//` 8 | 9 | - Once you have completed the assignment specified in the `/opt/se2001//README.md`, you have to run `synchro eval` from the respective assignment directory `~/se2001//` 10 | 11 | - If you get the below output, your code is passed and your submission is recorded. 12 | 13 | ``` 14 | Evaluation Successful. 15 | Submission Successful. 16 | ``` 17 | 18 | - Other useful packages installed 19 | - `tmux` a terminal multiplexer useful in splitting the terminal, recover your terminal session even when you disconnected from VM. 20 | - `batcat` a rust based alternative to `cat` that will display the file contents with color 21 | 22 | ## FAQ 23 | 24 | - I don't have the directory `se2001` in my home directory. What should I do? 25 | - Create the directory with `mkdir ~/se2001` 26 | - How to reset my password? 27 | 28 | - It will work only if you already have a password, otherwise the below won't work. 29 | - Execute the command `passwd` and provide your current password and new password as per the prompt. 30 | - The password typed will not be visible during and after the input. 31 | 32 | - How to reset my password if I forgot mine? 33 | - Send a mail to se2001@study.iitm.ac.in with subject `SE2001 VM PASSWORD RESET` 34 | - I am getting `Evaluation failed.` in my output, what should I do? 35 | - Submission failed means that your task is not completed properly, verify your script with the problem statement in `/opt/se2001//README.md`. 36 | - I am getting `Submission failed.` in my output, what should I do? 37 | - Submission failed means that your activity is not recorded, contact us through email/discourse. 38 | 39 | ## For other queries 40 | 41 | - Search for the relevant discourse post and comment on it, if there is no relevant then create one and assign the tag `vm` 42 | -------------------------------------------------------------------------------- /assignment_0/README.md: -------------------------------------------------------------------------------- 1 | Welcome to the your zeroth VM Task. This assignment is not graded and provided with a solution file. 2 | 3 | **IMPORTANT**: execute `synchro eval` from the assignment directory (for this assignment `~/se2001/assignment_0`) to record your submission for grading. 4 | 5 | # Assignment 0 (Not graded) 6 | 7 | Write a script `~/se2001/assignment_0/script.sh` that takes a filename as argument and print only the hash value. 8 | 9 | # Verification 10 | 11 | Once you have written your script you can verify the same using the following command 12 | 13 | ``` 14 | ~/se2001/assignment_0/script.sh hello.txt 15 | ``` 16 | 17 | The expected output should be 18 | 19 | ``` 20 | 133ee989293f92736301280c6f14c89d521200c17dcdcecca30cd20705332d44 21 | ``` 22 | -------------------------------------------------------------------------------- /assignment_0/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | RANDOM_NUMBER=$RANDOM 4 | RANDOM_FILE=/tmp/$RANDOM_NUMBER 5 | 6 | echo hola > $RANDOM_FILE 7 | 8 | if [[ "$(./script.sh $RANDOM_FILE)" == "133ee989293f92736301280c6f14c89d521200c17dcdcecca30cd20705332d44" ]]; then 9 | rm $RANDOM_FILE 10 | exit 0 11 | else 12 | rm $RANDOM_FILE 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /assignment_0/hello.txt: -------------------------------------------------------------------------------- 1 | hola 2 | -------------------------------------------------------------------------------- /assignment_0/script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | sha256sum "$1" | cut -d" " -f1 4 | -------------------------------------------------------------------------------- /assignment_1/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 1 2 | 3 | Write a script `script.sh` in `~/se2001/assignment_1` to download the file `sample_1.txt` from [http://local.server](http://local.server) and store it as `s1.txt` in `~/se2001/assignment_1/` 4 | 5 | Hint: Use `wget` command 6 | 7 | ## Optional 8 | 9 | If you are able to achieve the above task then, 10 | 11 | - Try to download the file `sample_2.txt`, `sample_3.txt` and `sample_4.txt`. 12 | - Use `cURL` to achieve the same. 13 | -------------------------------------------------------------------------------- /assignment_1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | if ! [ -f ~/se2001/assignment_1/script.sh ]; then 4 | echo "File $HOME/se2001/assignment_1/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x ~/se2001/assignment_1/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_1/script.sh is not executable" >&2 10 | exit 1 11 | fi 12 | 13 | ./script.sh 14 | 15 | if [ -f ~/se2001/assignment_1/s1.txt ]; then 16 | if diff /opt/localserver/sample_1.txt ~/se2001/assignment_1/s1.txt; then 17 | echo "File s1.txt validation successful" 18 | else 19 | echo "File s1.txt validation failed" >&2 20 | exit 1 21 | fi 22 | else 23 | echo "File s1.txt not found in ~/se2001/assignment_1" >&2 24 | exit 1 25 | fi 26 | 27 | for i in {2..4}; do 28 | if [ -f "$HOME/se2001/assignment_1/s$i.txt" ]; then 29 | if diff "/opt/localserver/sample_$i.txt" "$HOME/se2001/assignment_1/s$i.txt"; then 30 | echo "File s1.txt validation successful" >&2 31 | else 32 | echo "File s1.txt validation failed" >&2 33 | fi 34 | else 35 | echo "File s$i.txt not found in ~/se2001/assignment_1" >&2 36 | fi 37 | done 38 | -------------------------------------------------------------------------------- /assignment_10/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 10 2 | 3 | Write a script `~/se2001/assignment_10/script.sh` that takes a filename as argument and print only the MD5 hash value. 4 | 5 | The expected output should be 6 | 7 | ``` 8 | 916f4c31aaa35d6b867dae9a7f54270d 9 | ``` 10 | -------------------------------------------------------------------------------- /assignment_10/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | RANDOM_NUMBER=$RANDOM 4 | RANDOM_FILE=/tmp/$RANDOM_NUMBER 5 | 6 | echo hola >$RANDOM_FILE 7 | 8 | if ! [ -f ~/se2001/assignment_10/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_10/script.sh not found" >&2 10 | exit 1 11 | fi 12 | 13 | if ! [ -x ~/se2001/assignment_10/script.sh ]; then 14 | echo "File $HOME/se2001/assignment_10/script.sh is not executable" >&2 15 | exit 1 16 | fi 17 | 18 | if [[ "$(./script.sh $RANDOM_FILE)" == "916f4c31aaa35d6b867dae9a7f54270d" ]]; then 19 | rm $RANDOM_FILE 20 | exit 0 21 | else 22 | rm $RANDOM_FILE 23 | exit 1 24 | fi 25 | -------------------------------------------------------------------------------- /assignment_2/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 2 2 | 3 | Create a file named `.txt` in `~/se2001/assignment_2` and write a script `script.sh` in `~/se2001/assignment_2` to upload the file `.txt` to [http://local.server/upload/.txt](http://local.server/upload/.txt). 4 | 5 | Hint: 6 | - Use can verify the uploaded the file kept temporarily in the location `/tmp/local_uploads` 7 | - Use PUT request for while sending the file 8 | -------------------------------------------------------------------------------- /assignment_2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! [ -f ~/se2001/assignment_2/script.sh ]; then 4 | echo "File $HOME/se2001/assignment_2/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x ~/se2001/assignment_2/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_2/script.sh is not executable" >&2 10 | exit 1 11 | fi 12 | 13 | ~/se2001/assignment_2/script.sh 14 | 15 | if test -f "/tmp/local_uploads/$(whoami).txt"; then 16 | exit 0 17 | else 18 | echo "File not uploaded!" >&2 19 | echo "Check the URL that you have sent the file!" >&2 20 | exit 1 21 | fi 22 | -------------------------------------------------------------------------------- /assignment_3/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 3 2 | 3 | Define a function ` fibonacci(n) ` in file ` fibonacci.bc `. 4 | 5 | The function takes one positional argument which is an integer, say ` n `, and returns ` n `th Fibonacci number in Fibonacci sequence. 6 | 7 | Hint : Functions in ` bc `. 8 | 9 | ## Example : 10 | 11 | Fibonacci sequence : 0, 1, 1, 2, 3, 5, 8, 13, ..... 12 | 13 | If the function is invoked as ` fibonacci(5) `, then the output should be `3`, 14 | as ` 3 ` is at the ` 5 `th position in the Fibonacci sequence. 15 | -------------------------------------------------------------------------------- /assignment_3/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | if ! [ -f ~/se2001/assignment_3/fibonacci.bc ]; then 4 | echo "File $HOME/se2001/assignment_3/fibonacci.bc not found" >&2 5 | exit 1 6 | fi 7 | 8 | declare -A hash 9 | hash[49]=4807526976 10 | hash[83]=61305790721611591 11 | hash[121]=5358359254990966640871840 12 | hash[21]=6765 13 | hash[50]=7778742049 14 | 15 | for i in ${!hash[@]}; do 16 | 17 | sfibnum=$(bc -q fibonacci.bc <<< "fibonacci($i)") 18 | 19 | if [[ "$sfibnum" -ne "${hash[$i]}" ]]; 20 | then 21 | echo "Fibonacci evaluation failed" >&2; 22 | exit 1 23 | fi 24 | done 25 | echo "Fibonacci evaluation successful" 26 | -------------------------------------------------------------------------------- /assignment_4/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 4 2 | 3 | Create an account in GitHub and create a public repository named `se2001-` (in lowercase) and initialize with README.md 4 | 5 | Create a file named `script.sh` that exports two shell variables 6 | 7 | - `GITHUB_USERNAME` that holds the GitHub username Ex: "bscse2001" 8 | - `GITHUB_REPOSITORY` that holds the GitHub repository name Ex: "se2001-21f1000000" 9 | 10 | The repository can be deleted after the evaluation and submission of Assignment 5 is successful. 11 | -------------------------------------------------------------------------------- /assignment_4/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! [ -f ~/se2001/assignment_4/script.sh ]; then 4 | echo "File /home/$(whoami)/se2001/assignment_4/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | . "/home/$(whoami)/se2001/assignment_4/script.sh" 9 | 10 | if [ -z "$GITHUB_USERNAME" ]; then 11 | echo "GITHUB_USERNAME should not empty!" >&2 12 | exit 1 13 | fi 14 | 15 | if [ -z "$GITHUB_REPOSITORY" ]; then 16 | echo "GITHUB_REPOSITORY should not empty!" >&2 17 | exit 1 18 | fi 19 | 20 | if ! [ "$GITHUB_REPOSITORY" = "se2001-$(whoami)" ]; then 21 | echo "GITHUB_REPOSITORY is invalid!" >&2 22 | exit 1 23 | fi 24 | 25 | git ls-remote "https://github.com/$GITHUB_USERNAME/$GITHUB_REPOSITORY" || exit 1 26 | -------------------------------------------------------------------------------- /assignment_5/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 5 2 | 3 | Clone the repository that is created in Assignment 4 and keep it in ~/se2001/assignment_5/se2001-/ 4 | 5 | Create a file named `script.sh` that exports two shell variables 6 | 7 | - `GITHUB_USERNAME` that holds the GitHub username Ex: "bscse2001" 8 | - `GITHUB_REPOSITORY` that holds the GitHub repository name Ex: "se2001-21f1000000" 9 | 10 | **Sample file structure** 11 | 12 | ``` 13 | ~/se2001/assignment_5/ 14 | └── se2001-21f1000000 15 | └── README.md 16 | ``` 17 | -------------------------------------------------------------------------------- /assignment_5/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! [ -f ~/se2001/assignment_5/script.sh ]; then 4 | echo "File ~/se2001/assignment_5/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | . "/home/$(whoami)/se2001/assignment_5/script.sh" 9 | 10 | if [ -z "$GITHUB_USERNAME" ]; then 11 | echo "GITHUB_USERNAME should not empty!" >&2 12 | exit 1 13 | fi 14 | 15 | if [ -z "$GITHUB_REPOSITORY" ]; then 16 | echo "GITHUB_REPOSITORY should not empty!" >&2 17 | exit 1 18 | fi 19 | 20 | if ! [ "$GITHUB_REPOSITORY" = "se2001-$(whoami)" ]; then 21 | echo "GITHUB_REPOSITORY is invalid!" >&2 22 | exit 1 23 | fi 24 | 25 | ASSIGNMENT_DIRECTORY="/home/$(whoami)/se2001/assignment_5" 26 | REPOSITORY_DIRECTORY="/home/$(whoami)/se2001/assignment_5/se2001-$(whoami)" 27 | 28 | if ! [ -d "$REPOSITORY_DIRECTORY" ]; then 29 | echo "Directory ~/se2001/assignment_5/se2001-$(whoami) not found!" >&2 30 | exit 1 31 | fi 32 | 33 | if ! [ -d "$REPOSITORY_DIRECTORY/.git" ]; then 34 | echo "~/se2001/assignment_5/se2001-$(whoami) is not a valid git repository!" >&2 35 | exit 1 36 | fi 37 | 38 | if ! [ -f "$REPOSITORY_DIRECTORY/README.md" ]; then 39 | echo "File ~/se2001/assignment_5/se2001-$(whoami)/README.md not found!" >&2 40 | exit 1 41 | fi 42 | 43 | if ! git ls-remote "https://github.com/$GITHUB_USERNAME/$GITHUB_REPOSITORY" | cut -f1 | sort | uniq >.commits; then 44 | echo "Check the repository https://github.com/$GITHUB_USERNAME/$GITHUB_REPOSITORY" >&2 45 | exit 1 46 | fi 47 | 48 | cd "$REPOSITORY_DIRECTORY" || exit 1 49 | if ! git log | grep -q -f "$ASSIGNMENT_DIRECTORY/.commits"; then 50 | exit 1 51 | fi 52 | -------------------------------------------------------------------------------- /assignment_6/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 6 2 | 3 | Write a bash script ` script.sh ` to scrape a weather forecast website. 4 | 5 | The script takes 3 command line arguments 6 | 7 | * argument 1 8 | - ` city-name `. 9 | 10 | * argument 2 11 | - One of ` min ` and ` max ` refers to minimum temperature and maximum temperature respectively. 12 | 13 | * argument 3 14 | - One of ` mode ` and ` average `. 15 | - If you get more than one mode, your script should return the smallest mode value. 16 | 17 | The output 18 | * A number 19 | - Round of your answer to two decimal places. 20 | - i.e if the actual answer is `15.666666` , your answer should be `15.67` 21 | 22 | Url of weather forecast website : [http://weather.local](http://weather.local) 23 | 24 | Interpretation : 25 | 26 | ``` 27 | ./script.sh chennai min average 28 | 26 29 | ``` 30 | 31 | This returns the ` average ` of the ` min `imum temperature of city ` chennai ` on all days given in forecast. 32 | -------------------------------------------------------------------------------- /assignment_6/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! [ -f ~/se2001/assignment_6/script.sh ]; then 4 | echo "File $HOME/se2001/assignment_6/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x ~/se2001/assignment_6/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_6/script.sh is not executable" >&2 10 | exit 1 11 | fi 12 | 13 | temp="/tmp/.temp_$(whoami)" 14 | city=( "chennai" "patna" "gaya" "kanyakumari" "pune" "shillong" ) 15 | 16 | declare -A hash 17 | 18 | hash["chennai",0]=26 19 | hash["chennai",1]=26 20 | hash["chennai",2]=35 21 | hash["chennai",3]="34.83" 22 | 23 | hash["patna",0]=22 24 | hash["patna",1]="22.33" 25 | hash["patna",2]=37 26 | hash["patna",3]=37 27 | 28 | hash["gaya",0]=19 29 | hash["gaya",1]="18.67" 30 | hash["gaya",2]=37 31 | hash["gaya",3]="37.17" 32 | 33 | hash["kanyakumari",0]=24 34 | hash["kanyakumari",1]=24 35 | hash["kanyakumari",2]=36 36 | hash["kanyakumari",3]="35.83" 37 | 38 | hash["pune",0]=16 39 | hash["pune",1]="16.67" 40 | hash["pune",2]=34 41 | hash["pune",3]="34.17" 42 | 43 | hash["shillong",0]=11 44 | hash["shillong",1]="11.33" 45 | hash["shillong",2]=23 46 | hash["shillong",3]="23.17" 47 | 48 | arg2=("min" "max") 49 | 50 | arg3=( "mode" "average" ) 51 | 52 | num_cities=${#city[@]} 53 | 54 | p=0 55 | for i in {1..10}; do 56 | c=`shuf -i 0-$(( $num_cities-1 )) -n 1` 57 | idx2=`shuf -i 0-1 -n 1` 58 | if [ "${idx2}" -eq 0 ]; then 59 | idx3=`shuf -i 0-1 -n 1` 60 | a3=${arg3[idx3]} 61 | #echo $a3 62 | else 63 | idx3=`shuf -i 2-3 -n 1` 64 | if [ "$idx3" -eq 2 ]; 65 | then 66 | a3="mode"; 67 | else 68 | a3="average"; 69 | fi 70 | fi 71 | ans1="${hash[${city[c]},${idx3}]}" 72 | ./script.sh ${city[c]} ${arg2[${idx2}]} $a3 |& cat > "${temp}" 73 | 74 | if [ `wc -w < "${temp}"` -ne 1 ]; then 75 | exit 1 76 | fi 77 | 78 | cat "${temp}" | grep "[[:alpha:]]\|<\|>\||\|/\|°" > /dev/null 79 | if [ "$?" -eq 0 ]; then 80 | exit 1 81 | fi 82 | 83 | ans2=`cat "${temp}"` 84 | echo "$ans2" | grep "^[0-9]\+.\?[0-9]*$" > /dev/null 85 | if [ "$?" -eq 1 ]; then 86 | exit 1 87 | fi 88 | 89 | if [ `echo "${ans1} == ${ans2}" | bc` -eq 0 ]; then 90 | if [ $i -le 5 ]; then 91 | echo "INPUT : ${city[c]} ${arg2[${idx2}]} $a3" 92 | echo "OUTPUT : ${ans2}" 93 | echo "ANSWER : ${ans1}" 94 | echo -e "Test case $i failed.\n" >&2 95 | else 96 | p=$(( p+1 )) 97 | fi 98 | exit 1 99 | fi 100 | done 101 | rm "${temp}" 102 | if [ $p -gt 0 ]; then 103 | echo -e "$p/5 private test cases failed\n" >&2 104 | exit 1 105 | fi 106 | -------------------------------------------------------------------------------- /assignment_7/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 7 2 | 3 | The website has weather data about some cities in **India** as a snapshot at particular instant in time. Please, explore the website to know what data each page consists. 4 | 5 | Write a bash script ` script.sh ` using `jq` to parse and filter json data from weather API website. 6 | 7 | The script provides options below. 8 | 9 | | Option | Arg | Description | Output format | Example format | 10 | | :----:| :------: | :---------| :----- | :-------- | 11 | | | ` city-name ` | city name (required), the output city name should match API data | | | 12 | | ` -C ` | `min` | minimum temperature | json object | `{"name": , "temp_min": }` | 13 | | | ` max ` | maximum temperature | json object | `{"name": , "temp_max": }` | 14 | | | ` current ` | current temperature (`temp`) and it's Fahrenheit representation | json object | `{"name": , "temp": , "F": }` | 15 | | ` -W ` | | wind speed & it's square root | json object | `{"name": , "speed": , "sqrtspeed": }` | 16 | | ` -S ` | | city name, date, sunrise and sunset time in HH:MM:SS | json array | `[, DD/MM/YYYY, HH:MM:SS, HH:MM:SS]` | 17 | 18 | Weather API URL: [http://weather.local/api/v1/city/.json](http://weather.local/api/v1/city/.json) 19 | 20 | Some Rules : 21 | 22 | * The output must be pure ascii 23 | * The output indenation must 4 spaces for json object. 24 | 25 | Interpretation : 26 | 27 | ``` 28 | ~$ ./script.sh chennai -C min 29 | { 30 | "name": "Park Town", 31 | "temp_min": 31.67 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /assignment_7/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -f ~/se2001/assignment_7/script.sh ]; then 4 | echo "File $HOME/se2001/assignment_7/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x ~/se2001/assignment_7/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_7/script.sh is not executable" >&2 10 | exit 1 11 | fi 12 | 13 | 14 | temp_="/tmp/.temp_$(whoami)" 15 | city_=("chennai" "kolhapur" "amritsar" "pune" "srinagar" "surat" "cherrapunjee" "indore" "bikaner" "kalaburagi" "raipur" "bengaluru" "varanasi" "visakhapatnam") 16 | cur_=("31.67" "32.75" "23.97" "31.09" "11.95" "28.94" "20.33" "30.09" "29.66" "33.96" "32.07" "29.94" "30.99" "31.78") 17 | max_=("33.01" "32.75" "23.97" "31.09" "11.95" "28.94" "20.33" "30.09" "29.66" "33.96" "32.07" "30.73" "30.99" "31.78") 18 | min_=("31.67" "32.75" "21.9" "31.09" "11.95" "28.94" "20.33" "30.09" "29.66" "33.96" "32.07" "27.95" "30.99" "31.78") 19 | 20 | num_cities_="${#city_[@]}" 21 | opts_=( "-C" "-W" "-S" ) 22 | nopts_="${#opts_[@]}" 23 | cargs_=( "min" "max" "current" ) 24 | nargc_="${#cargs_[@]}" 25 | 26 | for i in {1..10}; 27 | do 28 | a_=1000 29 | c_=`shuf -i 1-$(( num_cities_ - 1 )) -n 1` 30 | o_=`shuf -i 1-$(( nopts_ - 1 )) -n 1` 31 | 32 | if [ "${o_}" -eq 0 ]; then 33 | a_=`shuf -i 0-$(( nargc_ - 1 )) -n 1` 34 | fi 35 | city_="${city_[c_]}" 36 | city_="${city_[c_]}" 37 | opt_="${opts_[o_]}" 38 | arg_="${cargs_[a_]}" 39 | min_t_="${min_[c_]}" 40 | max_t_="${max_[c_]}" 41 | cur_t_="${cur_[c_]}" 42 | ./script.sh "${city_}" "${opt_}" "${arg_}" > "${temp_}" 43 | 44 | if [ "$o_" -eq 0 ]; then 45 | case "$arg_" in 46 | "min" ) 47 | tmin_=`cat "${temp_}" | jq '.temp_min'` 48 | if [ "${tmin_}" != "${min_t_}" ]; then 49 | echo "Failed" >&2 50 | exit 1 51 | fi 52 | ;; 53 | 54 | "max" ) 55 | tmax_=`cat "${temp_}" | jq '.temp_max'` 56 | if [ "${tmax_}" != "${max_t_}" ]; then 57 | echo "Failed" >&2 58 | exit 1 59 | fi 60 | ;; 61 | 62 | "current" ) 63 | tcur_=`cat "${temp_}" | jq '.temp'` 64 | tfah_=`cat "${temp_}" | jq '.F'` 65 | if [ "${tcur_}" != "${cur_t_}" ]; then 66 | echo "Failed" >&2 67 | exit 1 68 | fi 69 | moc_=`echo "${tcur_} * 1.8 + 32" | bc` 70 | match_=`echo "${tfah_}" | grep "${moc_}"` 71 | if [ -z "${match_}" ]; then 72 | echo "Failed" >&2 73 | exit 1 74 | fi 75 | ;; 76 | esac 77 | fi 78 | 79 | if [ "${o_}" -eq 1 ]; then 80 | _w1=`cat "${temp_}" | jq '.speed' | grep '^[0-9]\{1\}.[0-9]\{1,2\}$'` 81 | _w2=`cat "${temp_}" | jq '.sqrtspeed' | grep '^[0-9]\+\.[0-9]\+$'` 82 | 83 | if [ "${_w1}" != "" ] && [ "${_w2}" != "" ]; then 84 | _sq1=`awk 'BEGIN { printf("%.2f", ARGV[1] ^ 0.5) }' "${_w1}"` 85 | _sq2=`awk 'BEGIN { printf("%.2f", ARGV[1])}' "${_w2}"` 86 | 87 | match_=`echo "${_sq1}" | grep "${_sq2}"` 88 | if [ -z "${match_}" ]; then 89 | echo "Failed" >&2 90 | exit 1 91 | fi 92 | else 93 | echo "Failed" >&2 94 | exit 1 95 | fi 96 | fi 97 | 98 | if [ "${o_}" -eq 2 ]; then 99 | list_=`cat "${temp_}"` 100 | npat_="^\"[[:alpha:]]\+[ ]\?[[:alpha:]]\+\"$" 101 | dpat_="^\"[0-3]\{1\}[0-9]\{1\}/[0-1]\{1\}[0-9]\{1\}/20[1-3]\{1\}[0-9]\{1\}\"$" 102 | tpat_="^\"[0-2][0-9]:[0-6][0-9]:[0-6][0-9]\"$" 103 | n_=`echo "${list_}" | jq .[0] | grep "${npat_}"` 104 | d_=`echo "${list_}" | jq .[1] | grep "${dpat_}"` 105 | r_=`echo "${list_}" | jq .[2] | grep "${tpat_}"` 106 | s_=`echo "${list_}" | jq .[3] | grep "${tpat_}"` 107 | if [ "${n_}" == "" ] && [ "${d_}" == "" ] && [ "${r_}" == "" ] && [ "${s_}" == "" ]; then 108 | echo "Failed" >&2 109 | exit 1 110 | fi 111 | fi 112 | done 113 | rm "${temp_}" 114 | -------------------------------------------------------------------------------- /assignment_8/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 8 2 | 3 | Git offers a feature called cherry pick which is used to pick a commit from different branch and apply into your branch. 4 | 5 | Your tasks are 6 | 7 | - Clone the git repository from `/opt/repository/fibonacci` to `~/se2001/assignment_8/fibonacci` using `git clone` 8 | - Create a branch `` from `master` 9 | - Replace the example fibonacci input by your roll number (final three digits without preceded zeroes) in the file README.md and do a commit with message `update example` 10 | - Cherry pick the commit `693dca7f5dae2b72a960018ba3df5b8819963b37` from the branch `remove-todo` and apply it your branch 11 | - Merge the branch `` to `main` locally. 12 | -------------------------------------------------------------------------------- /assignment_8/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if ! [ -d ~/se2001/assignment_8/fibonacci ]; then 4 | echo "Repository not cloned" 1>&2 5 | exit 1 6 | fi 7 | 8 | cd ~/se2001/assignment_8/fibonacci || exit 1 9 | 10 | CURRENT_BRANCH="$(git status | grep "On branch" | cut -d" " -f3-)" 11 | if ! git checkout "$(whoami)" >/dev/null 2>&1; then 12 | echo "Branch $(whoami) not found" >&2 13 | exit 1 14 | fi 15 | 16 | if ! git log | grep -q "update example"; then 17 | echo "Commit message \"update example\" not found in branch $(whoami)" >&2 18 | exit 1 19 | fi 20 | 21 | git checkout master >/dev/null 2>&1 22 | 23 | if ! git log | grep -q "update example"; then 24 | echo "Branch $(whoami) is not merged to the branch master" >&2 25 | exit 1 26 | fi 27 | 28 | if grep -q "^# TODO" ~/se2001/assignment_8/fibonacci/fib.sh; then 29 | echo "Cherry picked commit change not found in the branch master" 1>&2 30 | exit 1 31 | fi 32 | 33 | if ! [ "$(git cherry 693dca7f5dae2b72a960018ba3df5b8819963b37 | wc -l)" -gt 1 ]; then 34 | echo "Invalid commit: cherry picked commit" 35 | exit 1 36 | fi 37 | git checkout "$CURRENT_BRANCH" >/dev/null 2>&1 38 | -------------------------------------------------------------------------------- /assignment_9/README.md: -------------------------------------------------------------------------------- 1 | # Assignment 9 2 | 3 | Consider 4 | 5 | ## Iris flower data set 6 | 7 | * Source 8 | - Creator : R. A. Fischer 9 | - [https://archive.ics.uci.edu/ml/datasets/iris](https://archive.ics.uci.edu/ml/datasets/iris) 10 | 11 | ### Attribute Information 12 | 13 | 1. sepal length in cm 14 | 2. sepal width in cm 15 | 3. petal length in cm 16 | 4. petal width in cm 17 | 5. class: 18 | - Iris Setosa 19 | - Iris Versicolour 20 | - Iris Virginica 21 | 22 | The dataset is stored in a table in sqlite3 database. 23 | * Database name : ` iris-flower.sqlite3 ` 24 | * Table name : ` iris ` 25 | * Table Schema : ` CREATE TABLE iris (id INTEGER PRIMARY KEY AUTOINCREMENT, sepal_length REAL, sepal_width REAL, petal_length REAL, petal_width REAL, class VARCHAR(20)); ` 26 | 27 | * Find the database in this directory : ` /opt/iris ` 28 | 29 | Directory Structure : 30 | 31 | ```tree 32 | /opt/ 33 | |_ iris/ 34 | |_ iris-flower.sqlite3 35 | ``` 36 | 37 | Write a bash script ` script.sh ` to process iris data and return mean of a particular column of the dataset. 38 | 39 | The script will be invoked as follows: 40 | 41 | ```terminal 42 | ~$ ./script.sh 43 | ``` 44 | 45 | Argument 1 : 46 | 47 | * ` ` 48 | 49 | - ` setosa ` : For class Iris Setosa 50 | - ` versicolor ` : For class Iris Versicolour 51 | - ` virginica ` : For class Iris Virginica 52 | 53 | Argument 2 : 54 | 55 | * ` ` 56 | 57 | - ` sepal_length ` 58 | - ` sepal_width ` 59 | - ` petal_length ` 60 | - ` petal_width ` 61 | 62 | The output must be ` jq ` parsable. 63 | 64 | * ` jq ` parsable output : 65 | 66 | ``` 67 | {"class": , "feature": , "mean": } 68 | ``` 69 | 70 | * ` ` : This needs to be consistent with class names in sqlite3 database. 71 | * ` ` : Name of the feature. 72 | - If feature name in sqlite3 database is ` sepal_length ` this value should be ` Sepal length `. 73 | * ` ` : Mean of rows of ` ` over ` ` 74 | 75 | Round off ` ` up to 3 decimal places. 76 | 77 | 78 | 79 | 80 | Sample Example 81 | * Execution 82 | 83 | ``` 84 | ./script.sh setosa sepal_length 85 | ``` 86 | 87 | * Output 88 | 89 | ``` 90 | {"class":"Iris-setosa","feature":"Sepal length","mean":5.006} 91 | ``` 92 | 93 | Hint : 94 | 95 | * Use sql from command line to get the desired data. 96 | * Use ` echo ` to format the output in ` jq ` parsable form. 97 | -------------------------------------------------------------------------------- /assignment_9/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -f ~/se2001/assignment_9/script.sh ]; then 4 | echo "File $HOME/se2001/assignment_9/script.sh not found" >&2 5 | exit 1 6 | fi 7 | 8 | if ! [ -x ~/se2001/assignment_9/script.sh ]; then 9 | echo "File $HOME/se2001/assignment_9/script.sh is not executable" >&2 10 | exit 1 11 | fi 12 | 13 | classes=("setosa" "versicolor" "virginica") 14 | features=("sepal_length" "sepal_width" "petal_length" "petal_width") 15 | 16 | in="/opt/se2001/assignment_9/info.txt" 17 | 18 | ni=(1 3 5) 19 | fi=(1 2 3 4) 20 | 21 | nc="${#classes[@]}" 22 | nf="${#features[@]}" 23 | 24 | for i in {1..5}; do 25 | c=`shuf -i 0-$(( $nc-1 )) -n 1` 26 | f=`shuf -i 0-$(( $nf-1 )) -n 1` 27 | 28 | class="${classes[c]}" 29 | feature="${features[f]}" 30 | 31 | j="${ni[c]}" 32 | l="${fi[f]}" 33 | 34 | x=$( sed -ne "$j"p "${in}" | sed "s/[ ]\+/ /g" | cut -d " " -f "$l" ) 35 | js="$(./script.sh "$class" "$feature")" 36 | 37 | if [ -z "$js" ]; then 38 | exit 1; 39 | fi 40 | 41 | ca="Iris-${class}" 42 | fa="$(echo "${feature}" | sed "s/\(.*\)_\(.*\)/\u\1 \2/")" 43 | ce="$(echo "${js}" | jq -r ".class")" 44 | fe="$(echo "${js}" | jq -r ".feature")" 45 | me="$(echo "${js}" | jq -r ".mean")" 46 | 47 | mf="$(echo "${me} == ${x}" | bc)" 48 | 49 | if [ "${mf}" -eq 0 ] || [ "${ca}" != "${ce}" ] || [ "${fa}" != "${fe}" ]; then 50 | exit 1 51 | fi 52 | done 53 | -------------------------------------------------------------------------------- /assignment_9/info.txt: -------------------------------------------------------------------------------- 1 | 5.006 3.428 1.462 0.246 2 | 0.352 0.379 0.174 0.105 3 | 5.936 2.770 4.260 1.326 4 | 0.516 0.314 0.470 0.198 5 | 6.588 2.974 5.552 2.026 6 | 0.636 0.322 0.552 0.275 7 | -------------------------------------------------------------------------------- /practice_2.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 2 Problem 1 2 | 3 | There is a file named ` final.txt ` in the current working directory, that contains some text that you do not want it to be edited. 4 | 5 | Write a bash command to remove write permissions of user from this file. Do not edit any other file permissions. 6 | 7 | Note : Run ` synchro init ` to get the file ` final.txt ` to your solutions direcotry. 8 | -------------------------------------------------------------------------------- /practice_2.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dir="$(pwd)" 4 | 5 | [ `ls -l "$dir/final.txt" | cut -d " " -f 1` == "-r-xr--r--" ] && exit 0 || exit 1 6 | -------------------------------------------------------------------------------- /practice_2.1/init.sh: -------------------------------------------------------------------------------- 1 | touch final.txt 2 | chmod 744 final.txt 3 | echo "Final text" > final.txt 4 | -------------------------------------------------------------------------------- /practice_2.2/README.md: -------------------------------------------------------------------------------- 1 | # Week 2 Problem 2 2 | 3 | Write a bash script ` script.sh ` which prints the mime type of ` somefile ` located in ` ~/se2001/practice_2.2 `. 4 | 5 | Hint: Use ` file `. Refer manual of ` file ` or ` file --help `. 6 | 7 | Remember that: 8 | - Initially you may not find any file. 9 | - The files are automatically created when you run ` synchro eval `. 10 | - The same strategy is followed for most of the practice problems. 11 | - You can create dummy files to check for yourself if your script works. 12 | -------------------------------------------------------------------------------- /practice_2.2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | parent_dir="$(pwd)" 4 | test_dir="/opt/se2001/$(basename $parent_dir)" 5 | i=1 6 | for dir in "${test_dir}/test_case_"{1..3}; 7 | do 8 | cat ${dir}/input > ${parent_dir}/somefile 9 | 10 | oa=$(./script.sh) 11 | oe=$( cat ${dir}/output ) 12 | if [ "${oa}" != "${oe}" ]; 13 | then 14 | echo "Test case ${i} failed" 15 | exit 1 16 | fi 17 | (( i++ )) 18 | done 19 | 20 | -------------------------------------------------------------------------------- /practice_2.2/test_case_1/input: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello world 5 | 6 | 7 | Hello world 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /practice_2.2/test_case_1/output: -------------------------------------------------------------------------------- 1 | somefile: text/html 2 | -------------------------------------------------------------------------------- /practice_2.2/test_case_2/input: -------------------------------------------------------------------------------- 1 | def fib(n): 2 | a, b = 0, 1 3 | while a < n: 4 | print(a, end=' ') 5 | a, b = b, a + b 6 | print() 7 | fib(100) 8 | -------------------------------------------------------------------------------- /practice_2.2/test_case_2/output: -------------------------------------------------------------------------------- 1 | somefile: text/x-script.python 2 | -------------------------------------------------------------------------------- /practice_2.2/test_case_3/input: -------------------------------------------------------------------------------- 1 | { "body" : { "s1" : "vs1", "s2" : 2, "s3" : "vs3", "s4" : "vs4", "sub" : [ { "one" : 1, "two" : 2, "three" : 3, "four" : 4 }, { "one" : 1, "two" : 2, "three" : 3, "four" : 4 }, { "one" : 1, "two" : 2, "three" : 3, "four" : 4 } ] } } 2 | -------------------------------------------------------------------------------- /practice_2.2/test_case_3/output: -------------------------------------------------------------------------------- 1 | somefile: application/json 2 | -------------------------------------------------------------------------------- /practice_2.3/README.md: -------------------------------------------------------------------------------- 1 | # Week 2 Problem 3 2 | 3 | Write a bash script ` script.sh ` in directory ` ~/se2001/practice_2.3 ` to find the day of the week of April 1st of 2024 and print it to the output in full format with first letter capitalised. Ex: ` Wednesday ` 4 | 5 | Hint: Use ` date ` command. 6 | -------------------------------------------------------------------------------- /practice_2.3/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | d="Monday" 4 | ed=$(./script.sh) 5 | 6 | [ "${d}" == "${ed}" ] 7 | -------------------------------------------------------------------------------- /practice_3.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 3 Problem 1 2 | 3 | Write a command to append the contents of ` file1.txt ` to the start of ` file2.txt `. 4 | 5 | That is, the contents of ` file2.txt ` should be the contents of ` file1.txt ` followed by the contents ` file2.txt `. 6 | 7 | Note: 8 | - Use ` synchro init ` to initialize the files. 9 | -------------------------------------------------------------------------------- /practice_3.1/ans.txt: -------------------------------------------------------------------------------- 1 | Contents of File 1 2 | Contents of File 2 3 | -------------------------------------------------------------------------------- /practice_3.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ans_file="/opt/se2001/$(basename $(pwd))/ans.txt" 4 | 5 | diff "${ans_file}" file2.txt &>/dev/null 6 | -------------------------------------------------------------------------------- /practice_3.1/init.sh: -------------------------------------------------------------------------------- 1 | echo "Contents of File 1" > file1.txt 2 | echo "Contents of File 2" > file2.txt 3 | -------------------------------------------------------------------------------- /practice_3.2/README.md: -------------------------------------------------------------------------------- 1 | # Week 3 Problem 2 2 | 3 | Write a bash script ` script.sh ` to redirect the stderr and stdout of the command ` ls file1.txt file2.txt ` in that particular order to ` output.txt `. 4 | -------------------------------------------------------------------------------- /practice_3.2/ans.txt: -------------------------------------------------------------------------------- 1 | ls: cannot access 'file2.txt': No such file or directory 2 | file1.txt 3 | -------------------------------------------------------------------------------- /practice_3.2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | ans_file="/opt/se2001/$(basename $(pwd))/ans.txt" 2 | touch file1.txt 3 | bash script.sh 4 | diff "${ans_file}" output.txt &>/dev/null 5 | -------------------------------------------------------------------------------- /practice_4.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 1 2 | 3 | Consider a file named ` lsinfo.txt ` in your current working directory that contains output of the command ` ls -al ` run on some directory. 4 | 5 | 1. Use grep/egrep to print all the files/directories in file ` lsinfo.txt ` such that for those files/directories: 6 | 7 | 1. Owner has read and write permission only. 8 | 2. The group to which user belongs to has read permission only 9 | 3. Other users have read permission only 10 | 11 | Write your answer as a bash script ` script.sh `. Redirect your output to file ` out.txt `. 12 | 13 | Note: 14 | - Run ` synchro init ` before running ` synchro eval `. 15 | -------------------------------------------------------------------------------- /practice_4.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.1/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.1" 2 | cp $dir/lsinfo.txt . 3 | -------------------------------------------------------------------------------- /practice_4.1/lsinfo.txt: -------------------------------------------------------------------------------- 1 | total 260 2 | drwxrwxrwx 2 krishnan krishnan 258048 Jan 21 16:25 . 3 | drwxr-xr-x 49 krishnan krishnan 4096 Jan 21 16:28 .. 4 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 1A23045 5 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 1A3817 6 | -rwxr-xr-x 1 krishnan krishnan 0 Jan 21 16:21 1O23952 7 | -rwxr-xr-x 1 krishnan krishnan 0 Jan 21 16:25 1O7847 8 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 1U3433 9 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 1U4875 10 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 2A21279 11 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 2A9820 12 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 2O24193 13 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 2O24665 14 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:21 2U15879 15 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:25 2U31242 16 | -------rwx 1 krishnan krishnan 0 Jan 21 16:25 3A10505 17 | -------rwx 1 krishnan krishnan 0 Jan 21 16:21 3A27931 18 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3O17664 19 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 3O6190 20 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 3U15582 21 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3U20115 22 | -rw-r--rw- 1 krishnan krishnan 0 Jan 21 16:25 permdrw-r--r-- 23 | -------------------------------------------------------------------------------- /practice_4.1/output: -------------------------------------------------------------------------------- 1 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:21 2U15879 2 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:25 2U31242 3 | -------------------------------------------------------------------------------- /practice_4.10/1.cpp: -------------------------------------------------------------------------------- 1 | text 2 | void main{ //This is main function 3 | // But it does nothing 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/10.cp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/2.cpp: -------------------------------------------------------------------------------- 1 | void main(){ 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/3.cpp: -------------------------------------------------------------------------------- 1 | void somefunction(int x){ 2 | domain=5; 3 | return domain; 4 | } 5 | -------------------------------------------------------------------------------- /practice_4.10/4.cpp: -------------------------------------------------------------------------------- 1 | a// This is dummy 2 | -------------------------------------------------------------------------------- /practice_4.10/5.cpp: -------------------------------------------------------------------------------- 1 | void main() { //This is main function 2 | // But it does nothing 3 | return; 4 | } 5 | -------------------------------------------------------------------------------- /practice_4.10/6.cpp: -------------------------------------------------------------------------------- 1 | void main()typo{ 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/7.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/8.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/9.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.10/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 10 2 | 3 | Write the script ` script.sh ` to list the names of all the c++ files (i.e. with the extension ` .cpp `) in the current directory which contains a line such that 4 | 5 | - The line starts with the string ` void main() ` and ends with the character ` { `. There should be one or more spaces/tabs between the characters ` { ` and ` ) ` , but nothing except spaces. 6 | - For e.g the lines ` void main(){ `, ` void main() {}} ` are not a match for the above condition, but the lines ` void main() { `, ` void main() { ` are a match. 7 | 8 | And also print the count of these files in the following line. (Note: Try ` tee /dev/tty ` to the purpose). 9 | 10 | Store your output in file ` out.txt `. 11 | -------------------------------------------------------------------------------- /practice_4.10/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.10/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.10" 2 | cp $dir/*.cp* . 3 | -------------------------------------------------------------------------------- /practice_4.10/output: -------------------------------------------------------------------------------- 1 | 7.cpp 2 | 8.cpp 3 | 9.cpp 4 | 3 5 | -------------------------------------------------------------------------------- /practice_4.2/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 2 2 | 3 | Write a bash script ` script.sh ` to perform the following task, redirect your output to ` out.txt `. 4 | 5 | Consider a file named ` lsinfo.txt ` in your current working directory that contains output of the command ` ls -al ` run on some directory. 6 | 7 | Use grep/egrep to print the long-listing of all files excluding directories in ` lsinfo.txt ` whose last modified date is in January. 8 | 9 | Note: 10 | - There are many special kind of files in linux for example for socket files the first character in permission string is 's' like it is 'd' for directories. 11 | - Run ` synchro init ` to get ` lsinfo.txt ` in your ` pwd `. 12 | -------------------------------------------------------------------------------- /practice_4.2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.2/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.2" 2 | cp $dir/lsinfo.txt . 3 | -------------------------------------------------------------------------------- /practice_4.2/lsinfo.txt: -------------------------------------------------------------------------------- 1 | total 260 2 | drwxrwxrwx 2 krishnan krishnan 258048 Dec 21 16:25 . 3 | drwxr-xr-x 49 krishnan krishnan 4096 Jan 21 16:28 .. 4 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 1A23045 5 | -rw-rw-r-- 1 krishnan krishnan 0 Feb 21 16:25 1A3817 6 | drwxr-xr-x 1 krishnan krishnan 0 Jan 21 16:21 1O23952 7 | -rwxr-xr-x 1 krishnan krishnan 0 Jan 21 16:25 1O7847 8 | -rw-rw-r-- 1 krishnan krishnan 0 Mar 21 16:25 1U3433 9 | drw-rw-r-- 1 krishnan krishnan 0 Mar 21 16:21 1U4875 10 | -rw-rw-r-- 1 krishnan krishnan 0 Apr 21 16:21 2A21279 11 | drw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 2A9820 12 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 2O24193 13 | -rw-rw-r-- 1 krishnan krishnan 0 Nov 21 16:25 2O24665 14 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:21 2U15879 15 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:25 2U31242 16 | d------rwx 1 krishnan krishnan 0 Jan 21 16:25 3A10505 17 | d------rwx 1 krishnan krishnan 0 Feb 21 16:21 3A27931 18 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3O17664 19 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 3O6190 20 | -rw-rw-r-- 1 krishnan krishnan 0 Mar 21 16:21 3U15582 21 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3U20115 22 | -------------------------------------------------------------------------------- /practice_4.2/output: -------------------------------------------------------------------------------- 1 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 1A23045 2 | -rwxr-xr-x 1 krishnan krishnan 0 Jan 21 16:25 1O7847 3 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 2O24193 4 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:21 2U15879 5 | -rw-r--r-- 1 krishnan krishnan 0 Jan 21 16:25 2U31242 6 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3O17664 7 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:21 3O6190 8 | -rw-rw-r-- 1 krishnan krishnan 0 Jan 21 16:25 3U20115 9 | -------------------------------------------------------------------------------- /practice_4.3/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 3 2 | 3 | The command below gives the following output. 4 | 5 | ```bash 6 | $ cat twocities.txt 7 | It was the best of times, it was the worst of times, 8 | it was the age of wisdom, it was the age of foolishness, 9 | it was the epoch of belief, it was the epoch of incredulity, 10 | it was the season of Light, it was the season of Darkness, 11 | it was the spring of hope, it was the winter of despair, 12 | we had everything before us, we had nothing before us, 13 | we were all going direct to Heaven, we were all going direct the other way 14 | ``` 15 | 16 | Write a bash script ` script.sh ` to count and print the number of lines that starts with a capital letter and contains the word ` it ` (case-sensitive) in the above file. 17 | 18 | (a) Try a solution with only grep command. 19 | -------------------------------------------------------------------------------- /practice_4.3/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | n=$(bash script.sh) 4 | 5 | if [ "$n" != "2" ]; then 6 | exit 1 7 | fi 8 | -------------------------------------------------------------------------------- /practice_4.3/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.3" 2 | cp $dir/twocities.txt . 3 | -------------------------------------------------------------------------------- /practice_4.3/twocities.txt: -------------------------------------------------------------------------------- 1 | It was the best of times, it was the worst of times, 2 | it was the age of wisdom, it was the age of foolishness, 3 | it was the epoch of belief, it was the epoch of incredulity, 4 | it was the season of Light, it was the season of Darkness, 5 | it was the spring of hope, it was the winter of despair, 6 | we had everything before us, we had nothing before us, 7 | We were all going direct to Heaven, it was all bright 8 | -------------------------------------------------------------------------------- /practice_4.4/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 4 2 | 3 | The command below gives the following output. 4 | 5 | ```bash 6 | $ cat twocities.txt 7 | It was the best of times, it was the worst of times, 8 | it was the age of wisdom, it was the age of foolishness, 9 | it was the epoch of belief, it was the epoch of incredulity, 10 | it was the season of Light, it was the season of Darkness, 11 | it was the spring of hope, it was the winter of despair, 12 | we had everything before us, we had nothing before us, 13 | we were all going direct to Heaven, we were all going direct the other way 14 | ``` 15 | 16 | Write a bash script ` script.sh ` which satisfies the statement below: 17 | 18 | - ` out.txt ` contains all the lines that does not contain the word "we" in it. 19 | 20 | - Run ` synchro init ` to get started. 21 | -------------------------------------------------------------------------------- /practice_4.4/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.4/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.4" 2 | cp $dir/twocities.txt . 3 | -------------------------------------------------------------------------------- /practice_4.4/output: -------------------------------------------------------------------------------- 1 | It was the best of times, it was the worst of times, 2 | it was the age of wisdom, it was the age of foolishness, 3 | it was the epoch of belief, it was the epoch of incredulity, 4 | it was the season of Light, it was the season of Darkness, 5 | it was the spring of hope, it was the winter of despair, 6 | -------------------------------------------------------------------------------- /practice_4.4/twocities.txt: -------------------------------------------------------------------------------- 1 | It was the best of times, it was the worst of times, 2 | it was the age of wisdom, it was the age of foolishness, 3 | it was the epoch of belief, it was the epoch of incredulity, 4 | it was the season of Light, it was the season of Darkness, 5 | it was the spring of hope, it was the winter of despair, 6 | we had everything before us, we had nothing before us, 7 | We were all going direct to Heaven, it was all bright 8 | -------------------------------------------------------------------------------- /practice_4.5/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 5 2 | 3 | The file ` file.txt ` contains three fields in a line in the order 4 | 5 | - Country 6 | - Capital 7 | - Continent 8 | 9 | The first two fields country and capital are separated by a comma and the last two fields capital and continent are separated by a semicolon. 10 | 11 | The command below prints the file. 12 | 13 | ```bash 14 | $ cat file.txt 15 | India, New Delhi; Asia 16 | Czech Republic, Prague; Europe 17 | South Korea, Seoul; Asia 18 | Uzbekistan, Tashkent; Asia 19 | Mozambique, Maputo; Africa 20 | United Arab Emirates, Abu Dhabi; Asia 21 | Papua New Guinea, Port Moresby; Oceania 22 | Estonia, Tallinn; Europe 23 | Trinidad and Tobago, Port of Spain; South America 24 | Ghana, Accra; Africa 25 | ``` 26 | 27 | Write a bash script ` script.sh ` using ` cut ` to redirect only the countries and its capitals of ` file.txt ` in the format ` Country, Capital ` (Eg. ` India, New Delhi `) to file named ` out.txt `. 28 | 29 | -------------------------------------------------------------------------------- /practice_4.5/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.5/file.txt: -------------------------------------------------------------------------------- 1 | India, New Delhi; Asia 2 | Czech Republic, Prague; Europe 3 | South Korea, Seoul; Asia 4 | Uzbekistan, Tashkent; Asia 5 | Mozambique, Maputo; Africa 6 | United Arab Emirates, Abu Dhabi; Asia 7 | Papua New Guinea, Port Moresby; Oceania 8 | Estonia, Tallinn; Europe 9 | Trinidad and Tobago, Port of Spain; South America 10 | Ghana, Accra; Africa 11 | -------------------------------------------------------------------------------- /practice_4.5/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.5" 2 | cp $dir/file.txt . 3 | -------------------------------------------------------------------------------- /practice_4.5/output: -------------------------------------------------------------------------------- 1 | India, New Delhi 2 | Czech Republic, Prague 3 | South Korea, Seoul 4 | Uzbekistan, Tashkent 5 | Mozambique, Maputo 6 | United Arab Emirates, Abu Dhabi 7 | Papua New Guinea, Port Moresby 8 | Estonia, Tallinn 9 | Trinidad and Tobago, Port of Spain 10 | Ghana, Accra 11 | -------------------------------------------------------------------------------- /practice_4.6/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 6 2 | 3 | The command below gives the following output. 4 | 5 | ```bash 6 | $ cat twocities.txt 7 | It was the best of times, it was the worst of times, 8 | it was the age of wisdom, it was the age of foolishness, 9 | it was the epoch of belief, it was the epoch of incredulity, 10 | it was the season of Light, it was the season of Darkness, 11 | it was the spring of hope, it was the winter of despair, 12 | we had everything before us, we had nothing before us, 13 | we were all going direct to Heaven, we were all going direct the other way 14 | ``` 15 | 16 | Write bash script ` script.sh ` using grep to find all the lines that end with the letter ` s ` (comma and space at end should be excluded), in the above file. Redirect your output to file ` out.txt `. 17 | 18 | Note: 19 | - Run ` synchro init ` to begin. 20 | -------------------------------------------------------------------------------- /practice_4.6/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.6/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.6" 2 | cp $dir/twocities.txt . 3 | -------------------------------------------------------------------------------- /practice_4.6/output: -------------------------------------------------------------------------------- 1 | It was the best of times, it was the worst of times, 2 | it was the age of wisdom, it was the age of foolishness, 3 | it was the season of Light, it was the season of Darkness, 4 | we had everything before us, we had nothing before us, 5 | -------------------------------------------------------------------------------- /practice_4.6/twocities.txt: -------------------------------------------------------------------------------- 1 | It was the best of times, it was the worst of times, 2 | it was the age of wisdom, it was the age of foolishness, 3 | it was the epoch of belief, it was the epoch of incredulity, 4 | it was the season of Light, it was the season of Darkness, 5 | it was the spring of hope, it was the winter of despair, 6 | we had everything before us, we had nothing before us, 7 | We were all going direct to Heaven, it was all bright 8 | -------------------------------------------------------------------------------- /practice_4.7/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 7 2 | 3 | The command given below gives the following output. 4 | 5 | ```bash 6 | $ cat file.txt 7 | India, New Delhi; Asia 8 | Czech Republic, Prague; Europe 9 | South Korea, Seoul; Asia 10 | Uzbekistan, Tashkent; Asia 11 | Mozambique, Maputo; Africa 12 | United Arab Emirates, Abu Dhabi; Asia 13 | Papua New Guinea, Port Moresby; Oceania 14 | Estonia, Tallinn; Europe 15 | Trinidad and Tobago, Port of Spain; South America 16 | Ghana, Accra; Africa 17 | ``` 18 | 19 | Write a bash script ` script.sh ` to print all the countries in the file ` file.txt ` sorted alphabetically by name in reverse order. 20 | (Hint: Use the command ` sort -r ` to sort in reverse order) 21 | -------------------------------------------------------------------------------- /practice_4.7/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh >out.txt 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.7/file.txt: -------------------------------------------------------------------------------- 1 | India, New Delhi; Asia 2 | Czech Republic, Prague; Europe 3 | South Korea, Seoul; Asia 4 | Uzbekistan, Tashkent; Asia 5 | Mozambique, Maputo; Africa 6 | United Arab Emirates, Abu Dhabi; Asia 7 | Papua New Guinea, Port Moresby; Oceania 8 | Estonia, Tallinn; Europe 9 | Trinidad and Tobago, Port of Spain; South America 10 | Ghana, Accra; Africa 11 | -------------------------------------------------------------------------------- /practice_4.7/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.7" 2 | cp $dir/file.txt . 3 | -------------------------------------------------------------------------------- /practice_4.7/output: -------------------------------------------------------------------------------- 1 | Uzbekistan 2 | United Arab Emirates 3 | Trinidad and Tobago 4 | South Korea 5 | Papua New Guinea 6 | Mozambique 7 | India 8 | Ghana 9 | Estonia 10 | Czech Republic 11 | -------------------------------------------------------------------------------- /practice_4.8/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 8 2 | 3 | The command given below gives the following output. 4 | 5 | ```bash 6 | $ cat file.txt 7 | India, New Delhi; Asia 8 | Czech Republic, Prague; Europe 9 | South Korea, Seoul; Asia 10 | Uzbekistan, Tashkent; Asia 11 | Mozambique, Maputo; Africa 12 | United Arab Emirates, Abu Dhabi; Asia 13 | Papua New Guinea, Port Moresby; Oceania 14 | Estonia, Tallinn; Europe 15 | Trinidad and Tobago, Port of Spain; South America 16 | Ghana, Accra; Africa 17 | ``` 18 | 19 | Use the cut command to extract the continents (including the one white space in the beginning) of the first 5 lines of file.txt and store it in another file named continent.txt 20 | 21 | Write your answer as a script with name ` script.sh `. 22 | 23 | Note: 24 | - Run ` synchro init ` to begin. 25 | -------------------------------------------------------------------------------- /practice_4.8/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm continent.txt 2>/dev/null 4 | 5 | bash script.sh 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output continent.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.8/file.txt: -------------------------------------------------------------------------------- 1 | India, New Delhi; Asia 2 | Czech Republic, Prague; Europe 3 | South Korea, Seoul; Asia 4 | Uzbekistan, Tashkent; Asia 5 | Mozambique, Maputo; Africa 6 | United Arab Emirates, Abu Dhabi; Asia 7 | Papua New Guinea, Port Moresby; Oceania 8 | Estonia, Tallinn; Europe 9 | Trinidad and Tobago, Port of Spain; South America 10 | Ghana, Accra; Africa 11 | -------------------------------------------------------------------------------- /practice_4.8/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.8" 2 | cp $dir/file.txt . 3 | -------------------------------------------------------------------------------- /practice_4.8/output: -------------------------------------------------------------------------------- 1 | Asia 2 | Europe 3 | Asia 4 | Asia 5 | Africa 6 | -------------------------------------------------------------------------------- /practice_4.9/1.cpp: -------------------------------------------------------------------------------- 1 | text 2 | void main{ //This is main function 3 | // But it does nothing 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/10.cp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/2.cpp: -------------------------------------------------------------------------------- 1 | void main(){ 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/3.cpp: -------------------------------------------------------------------------------- 1 | void somefunction(int x){ 2 | domain=5; 3 | return domain; 4 | } 5 | -------------------------------------------------------------------------------- /practice_4.9/4.cpp: -------------------------------------------------------------------------------- 1 | a// This is dummy 2 | -------------------------------------------------------------------------------- /practice_4.9/5.cpp: -------------------------------------------------------------------------------- 1 | void main() { //This is main function 2 | // But it does nothing 3 | return; 4 | } 5 | -------------------------------------------------------------------------------- /practice_4.9/6.cpp: -------------------------------------------------------------------------------- 1 | void main()typo{ 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/7.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/8.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/9.cpp: -------------------------------------------------------------------------------- 1 | void main() { 2 | x = 5; 3 | printf(x); 4 | return; 5 | } -------------------------------------------------------------------------------- /practice_4.9/README.md: -------------------------------------------------------------------------------- 1 | # Week 4 Problem 9 2 | 3 | Write a bash script ` script.sh ` to list the names of all the c++ files (i.e. with the extension ` .cpp `) in the current directory which contains a line such that 4 | 5 | - The line starts with the string ` void main() ` and ends with the character ` { `. There should be one or more spaces/tabs between the characters ` { ` and ` ) ` , but nothing except spaces. 6 | - For e.g the lines ` void main(){ `, ` void main() {}} ` are not a match for the above condition, but the lines ` void main() { `, ` void main() { ` are a match. 7 | 8 | Note: 9 | Run ` synchro init ` to begin. 10 | -------------------------------------------------------------------------------- /practice_4.9/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm out.txt 2>/dev/null 4 | 5 | bash script.sh >out.txt 6 | 7 | dir="/opt/se2001/$(basename $(pwd))" 8 | diff $dir/output out.txt &>/dev/null 9 | -------------------------------------------------------------------------------- /practice_4.9/init.sh: -------------------------------------------------------------------------------- 1 | dir="/opt/se2001/practice_4.9" 2 | cp $dir/*.cp* . 3 | -------------------------------------------------------------------------------- /practice_4.9/output: -------------------------------------------------------------------------------- 1 | 7.cpp 2 | 8.cpp 3 | 9.cpp 4 | -------------------------------------------------------------------------------- /practice_5.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 1 2 | 3 | A school teaches from first to twelfth standard, each standard has 5 sections named as ` A ` to ` E `. 4 | 5 | The class room number is represented as standard (as number) followed by the section, for example ` 12E `, ` 3C `, etc.. 6 | 7 | Your task is to create a directory for every classroom in directory ` ~/se2001/practice_5.1 `. 8 | -------------------------------------------------------------------------------- /practice_5.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dir="$(pwd)" 4 | x=$(ls -d "${dir}/"* | sed -e "s/.*\///g" | sort -n) 5 | eo="/opt/se2001/$(basename $dir)/expected_output.txt" 6 | y=$(cat ${eo}) 7 | echo $x | grep -q "$y" && exit 0 || exit 1 8 | -------------------------------------------------------------------------------- /practice_5.1/expected_output.txt: -------------------------------------------------------------------------------- 1 | 1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E 5A 5B 5C 5D 5E 6A 6B 6C 6D 6E 7A 7B 7C 7D 7E 8A 8B 8C 8D 8E 9A 9B 9C 9D 9E 10A 10B 10C 10D 10E 11A 11B 11C 11D 11E 12A 12B 12C 12D 12E 2 | -------------------------------------------------------------------------------- /practice_5.10/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 10 2 | 3 | Write a bash script ` script.sh ` to redirect the **manual** entry (.i.e. output of man page) for the command which is specified as value of the shell variable named ` cmd ` to a text file ` man_commandValue.txt `, where ` commandValue ` is the value in variable ` cmd ` (example: if the variable ` cmd ` has value ` ls `, then redirect the out of `man ls` to the file named ` man_ls.txt ` ). 4 | 5 | If there is an error in getting the man page of command in variable ` cmd `, then redirect the standard error to ` man_commandValue.err ` and execute the help command for the command in variable ` cmd ` and redirect the output to the file ` man_commandValue.txt `, where ` commandValue ` is the value in variable ` cmd `. 6 | 7 | Hint: use operator && or || for executing help command based on exit status of first command. 8 | 9 | -------------------------------------------------------------------------------- /practice_5.10/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | for dir in $(ls $test_dir/ | grep "test_case" | sort); do 6 | read cmd <$test_dir/$dir/input 7 | cmd="$cmd" bash script.sh 8 | cmd="$cmd" bash $test_dir/$dir/getop 9 | diff ans.txt man_$cmd.txt &>/dev/null || exit 1 10 | diff ans.err man_$cmd.err &>/dev/null || exit 1 11 | done 12 | -------------------------------------------------------------------------------- /practice_5.10/test_case_1/getop: -------------------------------------------------------------------------------- 1 | man $cmd > ans.txt 2 | echo -n "">ans.err 3 | -------------------------------------------------------------------------------- /practice_5.10/test_case_1/input: -------------------------------------------------------------------------------- 1 | apropos 2 | -------------------------------------------------------------------------------- /practice_5.10/test_case_2/getop: -------------------------------------------------------------------------------- 1 | help $cmd > ans.txt 2 | man $cmd 1> /dev/null 2> ans.err 3 | -------------------------------------------------------------------------------- /practice_5.10/test_case_2/input: -------------------------------------------------------------------------------- 1 | fg 2 | -------------------------------------------------------------------------------- /practice_5.11/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 11 2 | 3 | Write a script ` script.sh ` to redirect the stderr of a command which is specified via variable ` cmd ` to a text file ` error.txt ` and print the stdout only if there is no error. 4 | 5 | Hint: Store the stdout to some file then based on success or failure of the command print that file. 6 | -------------------------------------------------------------------------------- /practice_5.11/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | test_txt=("Hello World") 6 | 7 | i=1 8 | for dir in $(ls $test_dir/ | grep "test_case" | sort); do 9 | read cmd <$test_dir/$dir/input 10 | echo ${test_txt[i - 1]} >output 11 | oa=$(cmd="$cmd" bash script.sh) 12 | read oe $tmp_file 13 | diff ${dir}/output $tmp_file 2> /dev/null 14 | if [ "$?" -ne 0 ]; then 15 | echo "Test case ${i} failed" 16 | exit 1 17 | fi 18 | (( i++ )) 19 | done 20 | -------------------------------------------------------------------------------- /practice_5.4/test_case_1/input: -------------------------------------------------------------------------------- 1 | /home/student78/daily.log 2 | -------------------------------------------------------------------------------- /practice_5.4/test_case_1/output: -------------------------------------------------------------------------------- 1 | daily.log 2 | /home/student78 3 | -------------------------------------------------------------------------------- /practice_5.4/test_case_2/input: -------------------------------------------------------------------------------- 1 | /etc/passwd 2 | -------------------------------------------------------------------------------- /practice_5.4/test_case_2/output: -------------------------------------------------------------------------------- 1 | passwd 2 | /etc 3 | -------------------------------------------------------------------------------- /practice_5.4/test_case_3/input: -------------------------------------------------------------------------------- 1 | /usr/bin/bash 2 | -------------------------------------------------------------------------------- /practice_5.4/test_case_3/output: -------------------------------------------------------------------------------- 1 | bash 2 | /usr/bin 3 | -------------------------------------------------------------------------------- /practice_5.5/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 5 2 | 3 | A shell variable named ` TOTALCOST ` contains a string which is in the format ` XYZ_ABC_PQR `, where ` XYZ `, ` ABC ` and ` PQR ` are three digit numbers. Underscore ` _ ` is used to separate the three digit numbers. 4 | 5 | Write a bash script ` script.sh ` that replaces all the underscores (` _ `) with commas (` , `) in the variable ` TOTALCOST ` and displays the final string on the screen. 6 | 7 | Example: ` TOTALCOST=198_890_128 ` 8 | 9 | **Output** 10 | 11 | ``` 12 | 198,890,128 13 | ``` 14 | -------------------------------------------------------------------------------- /practice_5.5/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=1 6 | for dir in "${test_dir}/test_case_"{1..3}; do 7 | read TOTALCOST <$dir/input 8 | export TOTALCOST 9 | oa=$(bash script.sh) 10 | read oe <${dir}/output 11 | if [ "${oa}" != "${oe}" ]; then 12 | echo "Test case ${i} failed" 13 | exit 1 14 | fi 15 | ((i++)) 16 | done 17 | -------------------------------------------------------------------------------- /practice_5.5/test_case_1/input: -------------------------------------------------------------------------------- 1 | 1_000 2 | -------------------------------------------------------------------------------- /practice_5.5/test_case_1/output: -------------------------------------------------------------------------------- 1 | 1,000 2 | -------------------------------------------------------------------------------- /practice_5.5/test_case_2/input: -------------------------------------------------------------------------------- 1 | 198_890_128 2 | -------------------------------------------------------------------------------- /practice_5.5/test_case_2/output: -------------------------------------------------------------------------------- 1 | 198,890,128 2 | -------------------------------------------------------------------------------- /practice_5.5/test_case_3/input: -------------------------------------------------------------------------------- 1 | 1_000_000_000_000 2 | -------------------------------------------------------------------------------- /practice_5.5/test_case_3/output: -------------------------------------------------------------------------------- 1 | 1,000,000,000,000 2 | -------------------------------------------------------------------------------- /practice_5.6/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 6 2 | 3 | Write a bash script ` script.sh ` to display only the filename without extension, whose absolute path is stored in a shell variable named ` file `. The extension should not include the dot ` . `. 4 | 5 | Example: ` file=/home/student56/tmp/artic.jpg ` 6 | 7 | **Output** 8 | 9 | ``` 10 | artic 11 | ``` 12 | -------------------------------------------------------------------------------- /practice_5.6/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=1 6 | for dir in "${test_dir}/test_case_"{1..3}; do 7 | read file <$dir/input 8 | export file 9 | oa=$(bash script.sh) 10 | read oe <${dir}/output 11 | if [ "${oa}" != "${oe}" ]; then 12 | echo "Test case ${i} failed" 13 | exit 1 14 | fi 15 | ((i++)) 16 | done 17 | -------------------------------------------------------------------------------- /practice_5.6/test_case_1/input: -------------------------------------------------------------------------------- 1 | /var/log/auth.log 2 | -------------------------------------------------------------------------------- /practice_5.6/test_case_1/output: -------------------------------------------------------------------------------- 1 | auth 2 | -------------------------------------------------------------------------------- /practice_5.6/test_case_2/input: -------------------------------------------------------------------------------- 1 | /home/student84/intro.mp4 2 | -------------------------------------------------------------------------------- /practice_5.6/test_case_2/output: -------------------------------------------------------------------------------- 1 | intro 2 | -------------------------------------------------------------------------------- /practice_5.6/test_case_3/input: -------------------------------------------------------------------------------- 1 | /home/student56/tmp/artic.jpg 2 | -------------------------------------------------------------------------------- /practice_5.6/test_case_3/output: -------------------------------------------------------------------------------- 1 | artic 2 | -------------------------------------------------------------------------------- /practice_5.7/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 7 2 | 3 | The string ` colors ` contains the name of the colors. 4 | Convert it to array of colors. 5 | 6 | Your task is to write a bash script ` script.sh ` to remove all vowels present in the array and display them. 7 | 8 | Example: ` colors="violet indigo blue green yellow orange red" ` 9 | 10 | Use the snippet below to convert a space separated string to an array. 11 | 12 | ```bash 13 | arr=($str) 14 | ``` 15 | 16 | **Output** 17 | 18 | ``` 19 | vlt ndg bl grn yllw rng rd 20 | ``` 21 | -------------------------------------------------------------------------------- /practice_5.7/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=1 6 | for dir in "${test_dir}/test_case_"{1..4}; do 7 | read colors <$dir/input 8 | export colors 9 | oa=$(bash script.sh) 10 | read oe <${dir}/output 11 | if [ "${oa}" != "${oe}" ]; then 12 | echo "Test case ${i} failed" 13 | exit 1 14 | fi 15 | ((i++)) 16 | done 17 | -------------------------------------------------------------------------------- /practice_5.7/test_case_1/input: -------------------------------------------------------------------------------- 1 | violet indigo blue green yellow orange red 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_1/output: -------------------------------------------------------------------------------- 1 | vlt ndg bl grn yllw rng rd 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_2/input: -------------------------------------------------------------------------------- 1 | red green blue 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_2/output: -------------------------------------------------------------------------------- 1 | rd grn bl 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_3/input: -------------------------------------------------------------------------------- 1 | red yellow blue 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_3/output: -------------------------------------------------------------------------------- 1 | rd yllw bl 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_4/input: -------------------------------------------------------------------------------- 1 | cmyk 2 | -------------------------------------------------------------------------------- /practice_5.7/test_case_4/output: -------------------------------------------------------------------------------- 1 | cmyk 2 | -------------------------------------------------------------------------------- /practice_5.8/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 8 2 | 3 | The variable ` filename ` has name of file along with the extension. 4 | 5 | Find the file extension and print it. 6 | 7 | Write your answer in bash script ` script.sh `. 8 | 9 | Note: 10 | - The variable will be made available during evaluation. 11 | 12 | Example, 13 | - If the filename is ` abc.txt `, print ` txt `. 14 | - If the filename is ` script.sh ` print ` sh `. 15 | -------------------------------------------------------------------------------- /practice_5.8/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=1 6 | for dir in $(ls $test_dir/ | grep "test_case" | sort); do 7 | read filename <"${test_dir}/${dir}"/input 8 | oa=$(filename="$filename" bash script.sh) 9 | read oe <"${test_dir}/${dir}"/output 10 | if [ "${oa}" != "${oe}" ]; then 11 | echo "Test case ${i} failed" 12 | exit 1 13 | fi 14 | ((i++)) 15 | done 16 | -------------------------------------------------------------------------------- /practice_5.8/test_case_1/input: -------------------------------------------------------------------------------- 1 | dummy.txt 2 | -------------------------------------------------------------------------------- /practice_5.8/test_case_1/output: -------------------------------------------------------------------------------- 1 | txt 2 | -------------------------------------------------------------------------------- /practice_5.8/test_case_2/input: -------------------------------------------------------------------------------- 1 | file.md 2 | -------------------------------------------------------------------------------- /practice_5.8/test_case_2/output: -------------------------------------------------------------------------------- 1 | md 2 | -------------------------------------------------------------------------------- /practice_5.9/README.md: -------------------------------------------------------------------------------- 1 | # Week 5 Problem 9 2 | 3 | The employee ID of a certain company is in the following format: ` DDYYPXXX ` where 4 | 5 | - ` DD ` stands for department; ex: FN for Finance, SD for Software Development 6 | - ` YY ` stands for work experience, which is a two digit number. 7 | - ` P ` stands for position, which is a letter; e.g. M for Manager, etc. 8 | - ` XXX ` stands for ID number. Which is a three digit number. 9 | 10 | Given three Employee IDs, extract just the Department and the ID Number of these employees. Redirect all the output to the file named ` output.txt `. 11 | 12 | The names of the variables which stores the employee Ids are shell variables with names ` eid1 `, ` eid2 ` and ` eid3 `. Redirect your output in the same sequence as ` sort -n ` order of the shell variable names. 13 | 14 | Write your code in file ` script.sh `. 15 | -------------------------------------------------------------------------------- /practice_5.9/ans.txt: -------------------------------------------------------------------------------- 1 | FN456 2 | SD729 3 | WO003 4 | -------------------------------------------------------------------------------- /practice_5.9/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | test_dir="/opt/se2001/$(basename $(pwd))" 2 | 3 | eid1="FN04M456" eid2="SD12C729" eid3="WO08W003" bash script.sh 4 | 5 | diff $test_dir/ans.txt output.txt &>/dev/null 6 | -------------------------------------------------------------------------------- /practice_7.1a/README.md: -------------------------------------------------------------------------------- 1 | # Week 7 Problem 1a 2 | 3 | Write a Bash script that accepts a name (string) as input from stdin and prints "hello input-name" as output, where input-name is the input string. 4 | 5 | Example: 6 | If the input string is, Raghu the output should be hello Raghu 7 | 8 | Write your script in the file script.sh. 9 | -------------------------------------------------------------------------------- /practice_7.1a/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i=1 4 | name=("Ravi" "Amit") 5 | for nam in "${name[@]}"; do 6 | oa="$( 7 | bash script.sh <script.sh and print "hello input-name" as output, where input-name is the input string. 4 | 5 | Example: 6 | 7 | If the command line input string is Raghu the output should be 8 | hello Raghu 9 | 10 | Write your script in the file script.sh. 11 | -------------------------------------------------------------------------------- /practice_7.1b/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i=1 4 | name=("Lalita" "Abhilasha") 5 | for nam in "${name[@]}"; do 6 | oa=$(bash script.sh $nam) 7 | oe="hello $nam" 8 | if [ "${oa}" != "${oe}" ]; then 9 | echo "Test case ${i} failed" 10 | exit 1 11 | fi 12 | ((i++)) 13 | done 14 | -------------------------------------------------------------------------------- /practice_7.1c/README.md: -------------------------------------------------------------------------------- 1 | # Week 7 Problem 1c 2 | 3 | Write a bash script that reads two numbers from the standard input and prints the sum of the numbers. Assume that the input will be numeric only. 4 | 5 | Write your script in the file script.sh. 6 | -------------------------------------------------------------------------------- /practice_7.1c/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i=1 4 | arr1=(235 1 143) 5 | arr2=(1 5 12344) 6 | for n in {0..2}; do 7 | oa="$( 8 | bash script.sh <out.txt #| tee out.txt 8 | 9 | diff out.txt ${test_dir}/${dir}/output &>/dev/null 10 | 11 | if [ "$?" -eq 1 ]; then 12 | echo "Test case $((i + 1)) failed" 13 | exit 1 14 | fi 15 | 16 | ((i++)) 17 | done 18 | -------------------------------------------------------------------------------- /practice_7.6/test_case_1/output: -------------------------------------------------------------------------------- 1 | * 2 | ** 3 | *** 4 | **** 5 | ***** 6 | ****** 7 | ******* 8 | ******** 9 | -------------------------------------------------------------------------------- /practice_7.6/test_case_2/output: -------------------------------------------------------------------------------- 1 | * 2 | ** 3 | *** 4 | **** 5 | ***** 6 | -------------------------------------------------------------------------------- /practice_7.6/test_case_3/output: -------------------------------------------------------------------------------- 1 | * 2 | ** 3 | *** 4 | -------------------------------------------------------------------------------- /practice_7.7/README.md: -------------------------------------------------------------------------------- 1 | # Week 7 Problem 7 2 | 3 | Write a bash script in ` script.sh ` file that takes an integer argument and prints whether the number is prime or not. If the number in the argument is a prime number, the program must print "Prime" and if not, it must print "Not Prime" 4 | -------------------------------------------------------------------------------- /practice_7.7/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i=1 4 | inp=(113 27 4 1) 5 | out=("Prime" "Not Prime" "Not Prime" "Not Prime") 6 | 7 | for n in {0..3}; 8 | do 9 | oa="$(bash script.sh ${inp[n]})" 10 | oe="${out[n]}" 11 | 12 | if [ "${oa}" != "${oe}" ]; 13 | then 14 | echo "Test case ${i} failed" 15 | exit 1 16 | fi 17 | (( i++ )) 18 | done 19 | -------------------------------------------------------------------------------- /practice_7.8/README.md: -------------------------------------------------------------------------------- 1 | # Week 7 Problem 8 2 | 3 | ` df -h ` gives the disk/filesystem usage information. Write a bash script to list all the filesystem mount point names based on their percentage usage divided in 5 categories in the format below. 4 | 5 | ```pseudo 6 | 0-50 7 | (names of filesystem one in each line with usage between 0 to 50%) 8 | 50-75 9 | (names of filesystem one in each line with usage between 50 to 75%) 10 | 75-85 11 | (names of filesystem one in each line with usage between 75 to 85%) 12 | 85-95 13 | (names of filesystem one in each line with usage between 85 to 95%) 14 | >95 15 | (names of filesystem one in each line with usage above 95%) 16 | ``` 17 | 18 | In each category, print the range in one line, followed by the filesystem mount point names. Print the range string even if there are no filesystems with usage in that range. Your script should not print anything else, all other errors and output from your script should be redirected to /dev/null. 19 | 20 | Write your script in file ` script.sh `. 21 | 22 | Filesystem mount point name is the last field in the output of df -h. 23 | 24 | The categories are 25 | 26 | - 0% to less than 50% usage. 27 | - 50% to less than 75% usage. 28 | - 75% to less than 85% usage. 29 | - 85% to less than 95% usage. 30 | - Equal and above 95% usage. 31 | 32 | Hint: Can store the df command output in a file. Then work on the file named ` dfOutput.txt ` line by line using the below script. 33 | 34 | ```Bash 35 | while read -r line; 36 | do 37 | echo $line; # To print the line. 38 | # Write your code to process the line. 39 | done < dfOutput.txt 40 | ``` 41 | 42 | Use ${var:0:-1} to remove the last character of string var. 43 | 44 | Note: 45 | - The file ` dfOutput.txt ` will be made available during evaluation. 46 | -------------------------------------------------------------------------------- /practice_7.8/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=1 6 | for dir in $(ls $test_dir/ | grep "test_case" | sort); do 7 | 8 | cp ${test_dir}/${dir}/input dfOutput.txt 9 | 10 | bash script.sh >out.txt 11 | 12 | diff out.txt ${test_dir}/${dir}/output &>/dev/null 13 | 14 | if [ "$?" -eq 1 ]; then 15 | echo "Test case $i failed" 16 | exit 1 17 | fi 18 | ((i++)) 19 | done 20 | -------------------------------------------------------------------------------- /practice_7.8/test_case_1/input: -------------------------------------------------------------------------------- 1 | Filesystem Size Used Avail Use% Mounted on 2 | tmpfs 389M 2.2M 387M 1% /run 3 | /dev/mapper/vgubuntu-root 27G 23G 2.5G 91% / 4 | tmpfs 1.9G 99M 1.9G 6% /dev/shm 5 | tmpfs 5.0M 4.0K 5.0M 1% /run/lock 6 | /dev/sda3 1.7G 288M 1.3G 19% /boot 7 | /dev/sda2 512M 6.1M 506M 2% /boot/efi 8 | tmpfs 389M 136K 389M 1% /run/user/1000 9 | /dev/sr0 127M 127M 0 100% /media/a/CDROM 10 | /dev/sr1 3.5G 3.5G 0 100% /media/a/Ubuntu 22.04 LTS amd64 11 | -------------------------------------------------------------------------------- /practice_7.8/test_case_1/output: -------------------------------------------------------------------------------- 1 | 0-50 2 | /run 3 | /dev/shm 4 | /run/lock 5 | /boot 6 | /boot/efi 7 | /run/user/1000 8 | 50-75 9 | 75-85 10 | 85-95 11 | / 12 | >95 13 | /media/a/CDROM 14 | /media/a/Ubuntu 22.04 LTS amd64 15 | -------------------------------------------------------------------------------- /practice_7.9/README.md: -------------------------------------------------------------------------------- 1 | # Week 7 Problem 9 2 | 3 | In Problem 8, modify the output of your script as below. 4 | 5 | - Print the range string only if there is a filesystem in that range. 6 | 7 | For example, if there is no filesystem with usage >95% and also none in the range 75-85, and the rest all range has at least one filesystem with usage in that range than your output should be 8 | 9 | ```pseudo 10 | 0-50 11 | (names of filesystem one in each line with usage between 0 to 50%) 12 | 50-75 13 | (names of filesystem one in each line with usage between 50 to 75%) 14 | 85-95 15 | (names of filesystem one in each line with usage between 85 to 95%) 16 | ``` 17 | 18 | Note: 19 | - ` dfOutput.txt ` will be made available during evaluation. 20 | -------------------------------------------------------------------------------- /practice_7.9/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | i=1 5 | for dir in $(ls $test_dir/ | grep "test_case" | sort); do 6 | cp $test_dir/${dir}/input dfOutput.txt 7 | 8 | bash script.sh >out.txt 9 | 10 | diff out.txt ${test_dir}/${dir}/output &>/dev/null 11 | 12 | if [ "$?" -eq 1 ]; then 13 | echo "Test case $i failed" 14 | exit 1 15 | fi 16 | ((i++)) 17 | done 18 | -------------------------------------------------------------------------------- /practice_7.9/test_case_1/input: -------------------------------------------------------------------------------- 1 | Filesystem Size Used Avail Use% Mounted on 2 | tmpfs 389M 2.2M 387M 1% /run 3 | /dev/mapper/vgubuntu-root 27G 23G 2.5G 91% / 4 | tmpfs 1.9G 98M 1.9G 6% /dev/shm 5 | tmpfs 5.0M 4.0K 5.0M 1% /run/lock 6 | /dev/sda3 1.7G 288M 1.3G 19% /boot 7 | /dev/sda2 512M 6.1M 506M 2% /boot/efi 8 | tmpfs 389M 136K 389M 1% /run/user/1000 9 | /dev/sr0 127M 127M 0 100% /media/a/CDROM 10 | /dev/sr1 3.5G 3.5G 0 100% /media/a/Ubuntu 22.04 LTS amd64 11 | -------------------------------------------------------------------------------- /practice_7.9/test_case_1/output: -------------------------------------------------------------------------------- 1 | 0-50 2 | /run 3 | /dev/shm 4 | /run/lock 5 | /boot 6 | /boot/efi 7 | /run/user/1000 8 | 85-95 9 | / 10 | >95 11 | /media/a/CDROM 12 | /media/a/Ubuntu 22.04 LTS amd64 13 | -------------------------------------------------------------------------------- /practice_8.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 8 Problem 1 2 | 3 | A software company has published some best practices for writing the code. One of the best practices mentioned is that no line in your code should exceed 50 characters in total including all types of characters or spaces. 4 | 5 | Write a bash script ` script.sh ` using sed that prints the names of all .c files that contain one or more lines with a length of more than 50 characters (as specified above). 6 | 7 | Hint: 8 | 9 | q [exit-code] 10 | Immediately quit the sed script without processing any more 11 | input, except that if auto-print is not disabled the cur‐ 12 | rent pattern space will be printed. The exit code argument 13 | is a GNU extension. 14 | 15 | Q [exit-code] 16 | Immediately quit the sed script without processing any more 17 | input. This is a GNU extension. 18 | 19 | Note: 20 | - The files will be made available during evaluation. 21 | -------------------------------------------------------------------------------- /practice_8.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | rm *.c 2>/dev/null 9 | eof="EOF" 10 | while read file; do 11 | if [[ $file =~ $eof ]]; then 12 | break 13 | fi 14 | rm $file 2>/dev/null 15 | while read line; do 16 | if [[ $line =~ $eof ]]; then 17 | break 18 | fi 19 | echo $line >>$file 20 | done 21 | done <$test_dir/$dir/input 22 | 23 | bash script.sh >out.txt 24 | 25 | diff out.txt $test_dir/${dir}/output &>/dev/null 26 | 27 | if [ "$?" -eq 1 ]; then 28 | echo "Test case $((i + 1)) failed" 29 | exit 1 30 | fi 31 | 32 | ((i++)) 33 | done 34 | -------------------------------------------------------------------------------- /practice_8.1/test_case_1/input: -------------------------------------------------------------------------------- 1 | helloworld.c 2 | #include 3 | int main() { 4 | printf("Hello world"); 5 | return 0; 6 | } 7 | EOF 8 | qandr.c 9 | #include 10 | int main() { 11 | int dd, dr, qt, rr; scanf("%d", &dd); scanf("%d", &dr); 12 | qt = dd / dr; 13 | rr = dd % dr; 14 | printf("quotient: %d\nremainder: %d", qt, rr); 15 | return 0; 16 | } 17 | EOF 18 | factorial.c 19 | #include 20 | int main() { 21 | int n; int i; long fact = 1; scanf("%d", &n); 22 | for (i = 1; i <= n; ++i) { fact *= i; } printf("%ld", fact); 23 | return 0; 24 | } 25 | EOF 26 | return0.c 27 | #include 28 | int main() { return 0; } 29 | EOF 30 | reverse.c 31 | #include 32 | int main() { 33 | int rr; int n = 0; int r = rr; scanf("%d", &n); 34 | while (n != 0) { rr = n % 10; r = r * 10 + rr; n /= 10; } 35 | printf("%d", r); return 0; 36 | } 37 | EOF 38 | EOF 39 | -------------------------------------------------------------------------------- /practice_8.1/test_case_1/output: -------------------------------------------------------------------------------- 1 | factorial.c 2 | qandr.c 3 | reverse.c 4 | -------------------------------------------------------------------------------- /practice_8.1/test_case_2/input: -------------------------------------------------------------------------------- 1 | helloworld.c 2 | #include 3 | int main() { 4 | printf("Hello world"); 5 | return 0; 6 | } 7 | EOF 8 | qandr.c 9 | #include 10 | int main() { 11 | int dd, dr, qt, rr; scanf("%d", &dd); scanf("%d", &dr); 12 | qt = dd / dr; 13 | rr = dd % dr; 14 | printf("quotient: %d\nremainder: %d", qt, rr); 15 | return 0; 16 | } 17 | EOF 18 | EOF 19 | -------------------------------------------------------------------------------- /practice_8.1/test_case_2/output: -------------------------------------------------------------------------------- 1 | qandr.c 2 | -------------------------------------------------------------------------------- /practice_8.1/test_case_3/input: -------------------------------------------------------------------------------- 1 | factorial.c 2 | #include 3 | int main() { 4 | int n; int i; long fact = 1; scanf("%d", &n); 5 | for (i = 1; i <= n; ++i) { fact *= i; } printf("%ld", fact); 6 | return 0; 7 | } 8 | EOF 9 | return0.c 10 | #include 11 | int main() { return 0; } 12 | EOF 13 | reverse.c 14 | #include 15 | int main() { 16 | int rr; int n = 0; int r = rr; scanf("%d", &n); 17 | while (n != 0) { rr = n % 10; r = r * 10 + rr; n /= 10; } 18 | printf("%d", r); return 0; 19 | } 20 | EOF 21 | EOF 22 | -------------------------------------------------------------------------------- /practice_8.1/test_case_3/output: -------------------------------------------------------------------------------- 1 | factorial.c 2 | reverse.c 3 | -------------------------------------------------------------------------------- /practice_8.2/README.md: -------------------------------------------------------------------------------- 1 | # Week 8 Problem 2 2 | 3 | Write a bash script ` script.sh ` using sed to print the contents of file ` $filename ` in the format ` : `. 4 | -------------------------------------------------------------------------------- /practice_8.2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | fname=("alphabet" "linefile" "twister") 6 | 7 | i=0 8 | 9 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 10 | filename="${fname[i]}" 11 | >$filename 12 | while true; do 13 | read line 14 | if [[ $line == "" ]]; then break; fi 15 | echo $line >>$filename 16 | done <$test_dir/$dir/input 17 | 18 | filename="$filename" bash script.sh >out.txt 19 | 20 | diff out.txt $test_dir/$dir/output &>/dev/null 21 | 22 | if [ "$?" -eq 1 ]; then 23 | echo "Test case $((i + 1)) failed" 24 | exit 1 25 | fi 26 | 27 | ((i++)) 28 | done 29 | -------------------------------------------------------------------------------- /practice_8.2/test_case_1/input: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | c 4 | d 5 | e 6 | f 7 | g 8 | h 9 | -------------------------------------------------------------------------------- /practice_8.2/test_case_1/output: -------------------------------------------------------------------------------- 1 | 1:a 2 | 2:b 3 | 3:c 4 | 4:d 5 | 5:e 6 | 6:f 7 | 7:g 8 | 8:h 9 | -------------------------------------------------------------------------------- /practice_8.2/test_case_2/input: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | -------------------------------------------------------------------------------- /practice_8.2/test_case_2/output: -------------------------------------------------------------------------------- 1 | 1:line 1 2 | 2:line 2 3 | 3:line 3 4 | -------------------------------------------------------------------------------- /practice_8.2/test_case_3/input: -------------------------------------------------------------------------------- 1 | How much wood would a woodchuck chuck if a woodchuck could chuck wood? 2 | He would chuck, he would, as much as he could, and chuck as much wood 3 | As a woodchuck would if a woodchuck could chuck wood 4 | -------------------------------------------------------------------------------- /practice_8.2/test_case_3/output: -------------------------------------------------------------------------------- 1 | 1:How much wood would a woodchuck chuck if a woodchuck could chuck wood? 2 | 2:He would chuck, he would, as much as he could, and chuck as much wood 3 | 3:As a woodchuck would if a woodchuck could chuck wood 4 | -------------------------------------------------------------------------------- /practice_8.3/README.md: -------------------------------------------------------------------------------- 1 | # Week 8 Problem 3 2 | 3 | The command ` cut -d " " -f 5 lsoutput ` is executed to extract the total size of the files. But the ` lsoutput ` contains multiple spaces between fields and for some reason we cannot change the cut command. Your task is to preprocess the file ` lsoutput ` to work with the cut command. 4 | 5 | Write a script ` script.sh ` to perform the task. 6 | 7 | Hint: Use the -i option in sed to do the modification in the file. 8 | 9 | Note: 10 | - ` lsoutput ` will be created during evaluation. 11 | -------------------------------------------------------------------------------- /practice_8.3/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | out=(57 17728 725) 6 | 7 | i=0 8 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 9 | >lsoutput 10 | while read line; do 11 | echo $line >>lsoutput 12 | done <$test_dir/$dir/input 13 | 14 | bash script.sh 15 | total=0 16 | for l in $(cut -d " " -f 5 lsoutput); do 17 | total=$((total + l)) 18 | done 19 | 20 | if [ "$total" -ne "${out[i]}" ]; then 21 | echo "Test case $((i + 1)) failed" 22 | exit 1 23 | fi 24 | 25 | ((i++)) 26 | done 27 | -------------------------------------------------------------------------------- /practice_8.3/test_case_1/input: -------------------------------------------------------------------------------- 1 | -rw-rw-r-- 1 krishnan krishnan 40 Feb 22 13:24 join.sed 2 | -rw-rw-r-- 1 krishnan krishnan 17 Feb 16 13:08 list_1 3 | -------------------------------------------------------------------------------- /practice_8.3/test_case_2/input: -------------------------------------------------------------------------------- 1 | -rw-rw-r-- 1 krishnan krishnan 180 Feb 4 11:27 employee_details.txt 2 | -rw-rw-r-- 1 krishnan krishnan 1092 Feb 23 20:36 expected 3 | -rwxrwxr-x 1 krishnan krishnan 16456 Feb 5 02:07 fact 4 | -------------------------------------------------------------------------------- /practice_8.3/test_case_3/input: -------------------------------------------------------------------------------- 1 | -rwxrw-r-- 2 krishnan krishnan 87 Feb 24 13:03 script.sh 2 | -rw-rw-r-- 1 krishnan krishnan 253 Feb 18 19:18 somefile.txt 3 | -rw-rw-r-- 1 krishnan krishnan 385 Feb 15 17:56 temp.py 4 | -------------------------------------------------------------------------------- /practice_8.4/README.md: -------------------------------------------------------------------------------- 1 | # Week 8 Problem 4 2 | 3 | In python, the multiline comments can be bounded by either ` ''' ` or ` """ `. 4 | 5 | Write a sed script ` script.sed ` that converts all the comments inside the triple quotes to single-line comment (preceded by #) and remove the lines inside the triple quotes that do not have any contents. 6 | 7 | **Sample Input:** 8 | 9 | ```python 10 | print(1) 11 | """ 12 | This is a comment 1 13 | """ 14 | print(2) 15 | """This is a comment 2 16 | """ 17 | print(3) 18 | """ 19 | This is a comment 3""" 20 | print(4) 21 | """This is a comment 4""" 22 | print(5) 23 | """This is a comment 5""" 24 | print(6) 25 | ``` 26 | 27 | **Sample Output** 28 | 29 | ```python 30 | print(1) 31 | #This is a comment 1 32 | print(2) 33 | #This is a comment 2 34 | print(3) 35 | #This is a comment 3 36 | print(4) 37 | #This is a comment 4 38 | print(5) 39 | #This is a comment 5 40 | print(6) 41 | ``` 42 | -------------------------------------------------------------------------------- /practice_8.4/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | >print.py 9 | while read line; do 10 | echo $line 11 | done <$test_dir/$dir/input >print.py 12 | 13 | sed -f script.sed print.py >out.txt 14 | 15 | diff out.txt $test_dir/$dir/output &>/dev/null 16 | 17 | if [ $? -eq 1 ]; then 18 | echo "Test case $((i + 1)) failed" 19 | exit 1 20 | fi 21 | 22 | ((i++)) 23 | done 24 | -------------------------------------------------------------------------------- /practice_8.4/test_case_1/input: -------------------------------------------------------------------------------- 1 | print(1) 2 | """ 3 | This is a comment 1 4 | """ 5 | print(2) 6 | """This is a comment 2 7 | """ 8 | print(3) 9 | """ 10 | This is a comment 3""" 11 | print(4) 12 | """This is a comment 4""" 13 | print(5) 14 | """This is a comment 5""" 15 | print(6) 16 | -------------------------------------------------------------------------------- /practice_8.4/test_case_1/output: -------------------------------------------------------------------------------- 1 | print(1) 2 | #This is a comment 1 3 | print(2) 4 | #This is a comment 2 5 | print(3) 6 | #This is a comment 3 7 | print(4) 8 | #This is a comment 4 9 | print(5) 10 | #This is a comment 5 11 | print(6) 12 | -------------------------------------------------------------------------------- /practice_8.4/test_case_2/input: -------------------------------------------------------------------------------- 1 | print(1) 2 | ''' 3 | This is a comment 1 4 | ''' 5 | print(2) 6 | '''This is a comment 2 7 | ''' 8 | print(3) 9 | ''' 10 | This is a comment 3''' 11 | print(4) 12 | '''This is a comment 4''' 13 | print(5) 14 | '''This is a comment 5''' 15 | print(6) 16 | -------------------------------------------------------------------------------- /practice_8.4/test_case_2/output: -------------------------------------------------------------------------------- 1 | print(1) 2 | #This is a comment 1 3 | print(2) 4 | #This is a comment 2 5 | print(3) 6 | #This is a comment 3 7 | print(4) 8 | #This is a comment 4 9 | print(5) 10 | #This is a comment 5 11 | print(6) 12 | -------------------------------------------------------------------------------- /practice_8.5/README.md: -------------------------------------------------------------------------------- 1 | # Week 8 Problem 5 2 | 3 | Write a sed script ` script.sed ` to extract the content inside every ` ` tags. 4 | 5 | Print all the non-empty extracted contents with leading and trail spaces trimmed in the source order. 6 | 7 | Note: Create environment array with name ` OPTS ` if more options to sed execution are required. 8 | 9 | **Sample Input** 10 | ``` 11 | 12 | 13 | Example script for sed 14 | 15 | 16 | 17 |

Welcome to sed programming

18 |

sed is a steam editor known for manipulation of text.
19 | sed can manipulate the text in the pipeline and can be used alond with other commands as well

20 | Frequently used options with sed 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
-n, --quiet, --silent suppress automatic printing of pattern space
-e script, --expression=script add the script to the commands to be executed
-f script-file, --file=script-file add the contents of script-file to the commands to be executed
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N specify the desired line-wrap length for the `l' command
-E, -r, --regexp-extended use extended regular expressions in the script (for portability use POSIX -E).
47 | 48 | 49 | ``` 50 | 51 | **Sample Output** 52 | 53 | ``` 54 | -n, --quiet, --silent 55 | suppress automatic printing of pattern space 56 | -e script, --expression=script 57 | add the script to the commands to be executed 58 | -f script-file, --file=script-file 59 | add the contents of script-file to the commands to be executed 60 | -i[SUFFIX], --in-place[=SUFFIX] 61 | edit files in place (makes backup if SUFFIX supplied) 62 | -l N, --line-length=N 63 | specify the desired line-wrap length for the `l' command 64 | -E, -r, --regexp-extended 65 | use extended regular expressions in the script (for portability use POSIX -E). 66 | ``` 67 | -------------------------------------------------------------------------------- /practice_8.5/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | cp $test_dir/$dir/input sedintro.html 9 | 10 | sed -n "${OPTS[@]}" -f script.sed sedintro.html >out.txt 11 | 12 | diff out.txt $test_dir/$dir/output &>/dev/null 13 | 14 | if [ $? -eq 1 ]; then 15 | echo "Test case $((i + 1)) failed" 16 | exit 1 17 | fi 18 | ((i + 1)) 19 | done 20 | -------------------------------------------------------------------------------- /practice_8.5/test_case_1/input: -------------------------------------------------------------------------------- 1 | 2 | 3 | Example script for sed 4 | 5 | 6 | 7 |

Welcome to sed programming

8 |

sed is a steam editor known for manipulation of text.
9 | sed can manipulate the text in the pipeline and can be used alond with other commands as well

10 | Frequently used options with sed 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
-n, --quiet, --silent suppress automatic printing of pattern space
-e script, --expression=script add the script to the commands to be executed
-f script-file, --file=script-file add the contents of script-file to the commands to be executed
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N specify the desired line-wrap length for the `l' command
-E, -r, --regexp-extended use extended regular expressions in the script (for portability use POSIX -E).
37 | 38 | 39 | -------------------------------------------------------------------------------- /practice_8.5/test_case_1/output: -------------------------------------------------------------------------------- 1 | -n, --quiet, --silent 2 | suppress automatic printing of pattern space 3 | -e script, --expression=script 4 | add the script to the commands to be executed 5 | -f script-file, --file=script-file 6 | add the contents of script-file to the commands to be executed 7 | -i[SUFFIX], --in-place[=SUFFIX] 8 | edit files in place (makes backup if SUFFIX supplied) 9 | -l N, --line-length=N 10 | specify the desired line-wrap length for the `l' command 11 | -E, -r, --regexp-extended 12 | use extended regular expressions in the script (for portability use POSIX -E). 13 | -------------------------------------------------------------------------------- /practice_9.1/README.md: -------------------------------------------------------------------------------- 1 | # Week 9 Problem 1 2 | 3 | Write an awk script in ` file.awk ` that can list nth Fibonacci number where ` n ` is a command line argument to the script. 4 | 5 | Note: The sequence is 1,1,2,3,5,..., and the first and the second value are 1 and 1. 6 | -------------------------------------------------------------------------------- /practice_9.1/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | i=1 4 | inp=(3 10 5 2) 5 | out=(2 55 5 1) 6 | 7 | for n in {0..3}; 8 | do 9 | oa="$(awk -f file.awk ${inp[n]})" 10 | oe="${out[n]}" 11 | 12 | if [ "${oa}" != "${oe}" ]; 13 | then 14 | echo "Test case ${i} failed" 15 | exit 1 16 | fi 17 | (( i++ )) 18 | done 19 | -------------------------------------------------------------------------------- /practice_9.2/README.md: -------------------------------------------------------------------------------- 1 | # Week 9 Problem 2 2 | 3 | Write an awk script ` file.awk ` to calculate class average marks of each subject and print each subject average in a new line. 4 | 5 | - The first line of output represents the class average of Mathematics. 6 | - The second line of output represents the class average of Physics. 7 | - The third line of output represents the class average of Chemistry. 8 | 9 | The marks are given in the comma separated file ` marks.csv `. 10 | 11 | Note: 12 | - ` marks.csv ` will be available during evaluation. 13 | -------------------------------------------------------------------------------- /practice_9.2/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | 9 | cat $test_dir/$dir/input >marks.csv 10 | 11 | awk -f file.awk marks.csv >out.txt 12 | 13 | diff out.txt $test_dir/$dir/output &>/dev/null 14 | 15 | if [ $? -eq 1 ]; then 16 | echo "Test case $((i + 1)) failed" 17 | exit 1 18 | fi 19 | ((i + 1)) 20 | done 21 | -------------------------------------------------------------------------------- /practice_9.2/test_case_1/input: -------------------------------------------------------------------------------- 1 | Name,Maths,Physics,Chemistry 2 | Jude,100,95,85 3 | Gayathri,85,99,92 4 | Priya,95,92,100 5 | Hari,97,89,99 6 | Ruban,87,98,95 7 | Madhu,85,100,96 8 | -------------------------------------------------------------------------------- /practice_9.2/test_case_1/output: -------------------------------------------------------------------------------- 1 | 91.5 2 | 95.5 3 | 94.5 4 | -------------------------------------------------------------------------------- /practice_9.3/README.md: -------------------------------------------------------------------------------- 1 | # Week 9 Problem 3 2 | 3 | Write an awk script ` union.awk ` to get when combined, the distinct (union) lines among two files ` file1 ` and ` file2 `. 4 | 5 | The printed lines are based on the sequence of occurrence from ` file1 ` to ` file2 `. 6 | 7 | Hint: Use the predefined variables NR and FNR 8 | -------------------------------------------------------------------------------- /practice_9.3/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | 9 | awk -f union.awk $test_dir/$dir/file1 $test_dir/$dir/file2 >out.txt 10 | 11 | diff out.txt $test_dir/$dir/output &>/dev/null 12 | 13 | if [ $? -eq 1 ]; then 14 | echo "Test case $((i + 1)) failed" 15 | exit 1 16 | fi 17 | 18 | ((i++)) 19 | done 20 | -------------------------------------------------------------------------------- /practice_9.3/test_case_1/file1: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | -------------------------------------------------------------------------------- /practice_9.3/test_case_1/file2: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /practice_9.3/test_case_1/output: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | -------------------------------------------------------------------------------- /practice_9.3/test_case_2/file1: -------------------------------------------------------------------------------- 1 | abcd 2 | efgh 3 | ijk 4 | -------------------------------------------------------------------------------- /practice_9.3/test_case_2/file2: -------------------------------------------------------------------------------- 1 | ijkl 2 | ef 3 | abcd 4 | -------------------------------------------------------------------------------- /practice_9.3/test_case_2/output: -------------------------------------------------------------------------------- 1 | abcd 2 | efgh 3 | ijk 4 | ijkl 5 | ef 6 | -------------------------------------------------------------------------------- /practice_9.4/README.md: -------------------------------------------------------------------------------- 1 | # Week 9 Problem 4 2 | 3 | Write an AWK script in ` script.awk ` to count the number of lines in the file. 4 | -------------------------------------------------------------------------------- /practice_9.4/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | out=(2 8 3) 6 | 7 | i=0 8 | 9 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 10 | cat $test_dir/$dir/input >file 11 | 12 | oa=$(awk -f script.awk file) 13 | oe=${out[i]} 14 | 15 | if [ "$oa" -ne "$oe" ]; then 16 | echo "Test case $((i + 1)) failed" 17 | exit 1 18 | fi 19 | 20 | ((i++)) 21 | done 22 | -------------------------------------------------------------------------------- /practice_9.4/test_case_1/input: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | -------------------------------------------------------------------------------- /practice_9.4/test_case_2/input: -------------------------------------------------------------------------------- 1 | abcd 2 | efgh 3 | fa 4 | f 5 | e 6 | f 7 | e 8 | waf 9 | -------------------------------------------------------------------------------- /practice_9.4/test_case_3/input: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | c 4 | -------------------------------------------------------------------------------- /practice_9.5/README.md: -------------------------------------------------------------------------------- 1 | # Week 9 Problem 5 2 | 3 | The ` uniq ` command in the Linux will not print the adjacent duplicate lines. Write an AWK script ` script.awk ` to the same. 4 | -------------------------------------------------------------------------------- /practice_9.5/evaluation_file.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test_dir="/opt/se2001/$(basename $(pwd))" 4 | 5 | i=0 6 | 7 | for dir in $(ls "$test_dir" | grep "test_case" | sort); do 8 | while read -r line; do 9 | [[ $line == "" ]] && break 10 | echo $line 11 | done <$test_dir/$dir/input >file 12 | 13 | awk -f script.awk file >out.txt 14 | 15 | diff out.txt $test_dir/$dir/output &>/dev/null 16 | 17 | if [ $? -eq 1 ]; then 18 | echo "Test case $((i + 1)) failed" 19 | exit 1 20 | fi 21 | 22 | ((i++)) 23 | done 24 | -------------------------------------------------------------------------------- /practice_9.5/test_case_1/input: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 2 13 | -------------------------------------------------------------------------------- /practice_9.5/test_case_1/output: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /practice_9.5/test_case_2/input: -------------------------------------------------------------------------------- 1 | ABCD 2 | abcd 3 | apple 4 | a 5 | s 6 | w 7 | f 8 | e 9 | a 10 | a 11 | f 12 | -------------------------------------------------------------------------------- /practice_9.5/test_case_2/output: -------------------------------------------------------------------------------- 1 | ABCD 2 | abcd 3 | apple 4 | a 5 | s 6 | w 7 | f 8 | e 9 | a 10 | f 11 | --------------------------------------------------------------------------------