From 4b02c825b75e2ffb86335bc9089719c31e331b2c Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 30 Nov 2022 17:38:56 +0000 Subject: [PATCH] feat(skip-lines): add subject, test and solution for the exercise skip-line --- sh/tests/skip-lines_test.sh | 11 ++++++++ sh/tests/solutions/skip-lines.sh | 3 ++ subjects/skip-lines/README.md | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100755 sh/tests/skip-lines_test.sh create mode 100755 sh/tests/solutions/skip-lines.sh create mode 100644 subjects/skip-lines/README.md diff --git a/sh/tests/skip-lines_test.sh b/sh/tests/skip-lines_test.sh new file mode 100755 index 000000000..0ac11e4ac --- /dev/null +++ b/sh/tests/skip-lines_test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +submitted=$(bash student/skip-lines.sh) +expected=$(bash solutions/skip-lines.sh) + +diff <(echo "$submitted") <(echo "$expected") diff --git a/sh/tests/solutions/skip-lines.sh b/sh/tests/solutions/skip-lines.sh new file mode 100755 index 000000000..7898491f5 --- /dev/null +++ b/sh/tests/solutions/skip-lines.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ls -l | sed -n 'n;p' diff --git a/subjects/skip-lines/README.md b/subjects/skip-lines/README.md new file mode 100644 index 000000000..13e21e86b --- /dev/null +++ b/subjects/skip-lines/README.md @@ -0,0 +1,47 @@ +## Skip lines + +### Instructions + +Write a command line in a `skip-lines.sh` file that prints the result of a `ls -l` skipping 1 line out of 2, starting with the **first** one. + +Example: + +```console +User-> ls -l +drwxr-xr-x 16 User User 4096 nov 11 10:55 Desktop +drwxr-xr-x 22 User User 4096 nov 4 10:02 Documents +drwxr-xr-x 6 User User 4096 nov 11 10:40 Downloads +drwxr-xr-x 2 User User 4096 mar 31 2022 Music +drwxr-xr-x 2 User User 4096 set 29 10:34 Pictures +drwxr-xr-x 2 User User 4096 nov 23 2021 Public +``` + +What we want your script to do is: + +```console +drwxr-xr-x 16 User User 4096 nov 11 10:55 Desktop +drwxr-xr-x 6 User User 4096 nov 11 10:40 Downloads +drwxr-xr-x 2 User User 4096 set 29 10:34 Pictures +``` + +**Tips:** + +Here are some Commands that can help you: + +- `sed`. Edit text in a scriptable manner. You can see also: awk. [For more information](https://www.gnu.org/software/sed/manual/sed.html). + + - Print just a first line to stdout: + `{{command}} | sed -n '1p'` + +```console +User-> cat file +AIX +Solaris +Unix +Linux +HPUX +User-> sed -n '1p' file +AIX +``` + +Use man to see how `awk` or `sed` works, they can do the job.