From 1f284b5c43a0294a4c3bd7120c43c79d6323329d Mon Sep 17 00:00:00 2001 From: Zouhair AMAZZAL Date: Sat, 3 Dec 2022 03:00:42 +0100 Subject: [PATCH] feat(find-files-extention): add subject, test and solution for new a exercise --- .../find-files-extension/folder1/file1.txt | 0 .../find-files-extension/folder1/file2.txt | 0 .../find-files-extension/folder1/file3.txt | 0 .../find-files-extension/folder1/test4.sh | 0 .../folder2/fileInsideAfolder4.txt | 0 sh/tests/find-files-extension/folder2/test.sh | 0 .../folder2/testtxt/fileInsideAfolder5.txt | 0 .../testtxt/test/fileInsideAfolder6.txt | 0 .../folder2/testtxt/test/lol.sh | 0 sh/tests/find-files-extension_test.sh | 18 ++++++ sh/tests/solutions/find-files-extension.sh | 3 + subjects/find-files-extension/README.md | 59 +++++++++++++++++++ 12 files changed, 80 insertions(+) create mode 100644 sh/tests/find-files-extension/folder1/file1.txt create mode 100644 sh/tests/find-files-extension/folder1/file2.txt create mode 100644 sh/tests/find-files-extension/folder1/file3.txt create mode 100644 sh/tests/find-files-extension/folder1/test4.sh create mode 100644 sh/tests/find-files-extension/folder2/fileInsideAfolder4.txt create mode 100644 sh/tests/find-files-extension/folder2/test.sh create mode 100644 sh/tests/find-files-extension/folder2/testtxt/fileInsideAfolder5.txt create mode 100644 sh/tests/find-files-extension/folder2/testtxt/test/fileInsideAfolder6.txt create mode 100644 sh/tests/find-files-extension/folder2/testtxt/test/lol.sh create mode 100755 sh/tests/find-files-extension_test.sh create mode 100755 sh/tests/solutions/find-files-extension.sh create mode 100644 subjects/find-files-extension/README.md diff --git a/sh/tests/find-files-extension/folder1/file1.txt b/sh/tests/find-files-extension/folder1/file1.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder1/file2.txt b/sh/tests/find-files-extension/folder1/file2.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder1/file3.txt b/sh/tests/find-files-extension/folder1/file3.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder1/test4.sh b/sh/tests/find-files-extension/folder1/test4.sh new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder2/fileInsideAfolder4.txt b/sh/tests/find-files-extension/folder2/fileInsideAfolder4.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder2/test.sh b/sh/tests/find-files-extension/folder2/test.sh new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder2/testtxt/fileInsideAfolder5.txt b/sh/tests/find-files-extension/folder2/testtxt/fileInsideAfolder5.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder2/testtxt/test/fileInsideAfolder6.txt b/sh/tests/find-files-extension/folder2/testtxt/test/fileInsideAfolder6.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension/folder2/testtxt/test/lol.sh b/sh/tests/find-files-extension/folder2/testtxt/test/lol.sh new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/find-files-extension_test.sh b/sh/tests/find-files-extension_test.sh new file mode 100755 index 000000000..0fe8afd48 --- /dev/null +++ b/sh/tests/find-files-extension_test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge() { + submitted=$(cd "$1" && bash "$script_dirS"/student/find-files-extension.sh) + expected=$(cd "$1" && bash "$script_dirS"/solutions/find-files-extension.sh) + + diff <(echo "$submitted") <(echo "$expected") +} + +challenge find-files-extension/folder1 +challenge find-files-extension/folder2 diff --git a/sh/tests/solutions/find-files-extension.sh b/sh/tests/solutions/find-files-extension.sh new file mode 100755 index 000000000..503c78762 --- /dev/null +++ b/sh/tests/solutions/find-files-extension.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +find . -iregex '.*\.\(txt\)' -exec basename {} \; | cut -d "." -f 1 \ No newline at end of file diff --git a/subjects/find-files-extension/README.md b/subjects/find-files-extension/README.md new file mode 100644 index 000000000..7b8f3af8c --- /dev/null +++ b/subjects/find-files-extension/README.md @@ -0,0 +1,59 @@ +## find-files-extension + +### Instructions + +Create a file `find-files-extension.sh`, which will look, from the current directory and its sub-folders for: + +all the files with `.txt` extension. + +That command will only show the name of the files without the extension `.txt`. + +- You can use this for testing: https://assets.01-edu.org/devops-branch/find-files-extension-example.zip + +- What to use : `find` + +- The output should be exactly like the example bellow but with the expected name + +```console +$pwd +<..>/find-files-extension-example +$./find-files-extension.sh | cat -e +qwep$ +pq1$ +zzzz$ +ziko$ +wei$ +ek$ +$ +``` + +### Hints + +`find` command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments: +You can use REGEX in `find` command. + +```console +$find ~/ -iregex '' + +$ +``` +REGEX for txt files: `.*\.\(txt\)` + +`cut` command is a command-line utility that allows you to cut out sections of a specified file or piped data and print the result: + +```console +$cat cut-example.txt +abc-lol +testtest-abcx +qwerty-azerty-x +$cat cut-example.txt | cut -d "-" -f 1 # cut the lines with "-" as delimiter and print the first part. +abc +testtest +qwerty +$ +``` + +May you will need to use `pipe (|)` and `&&`. + +> You have to use Man or Google to know more about commands flags, in order to solve this exercice! +> Google and Man will be your friends! \ No newline at end of file