Skip to content

Commit c35ce92

Browse files
sed exercises complete
1 parent 5f214aa commit c35ce92

File tree

6 files changed

+9
-0
lines changed

6 files changed

+9
-0
lines changed

individual-shell-tools/sed/script-01.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
set -euo pipefail
44

55
# TODO: Write a command to output input.txt with all occurrences of the letter `i` replaced with `I`.
6+
sed "s/i/I/g" input.txt
67
# The output should contain 11 lines.
78
# The first line of the output should be: "ThIs Is a sample fIle for experImentIng with sed.".

individual-shell-tools/sed/script-02.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
set -euo pipefail
44

55
# TODO: Write a command to output input.txt with numbers removed.
6+
sed 's/[0-9]//g' input.txt
7+
68
# The output should contain 11 lines.
79
# Line 6 of the output should be " Alisha".

individual-shell-tools/sed/script-03.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
set -euo pipefail
44

55
# TODO: Write a command to output input.txt removing any line which contains a number.
6+
sed '/[0-9]/d' input.txt
7+
68
# The output should contain 6 lines.

individual-shell-tools/sed/script-04.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
set -euo pipefail
44

55
# TODO: Write a command to output input.txt replacing every occurrence of the string "We'll" with "We will".
6+
sed "s/We'll/We will/g" input.txt
67
# The output should contain 11 lines.

individual-shell-tools/sed/script-05.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ set -euo pipefail
44

55
# TODO: Write a command to output input.txt with one change:
66
# If a line starts with a number and a space, make the line instead end with a space and the number.
7+
sed 's/^\([0-9]\+\) \(.*\)/\2 \1/' input.txt
78
# So line 6 which currently reads "37 Alisha" should instead read "Alisha 37".
89
# The output should contain 11 lines.

individual-shell-tools/sed/script-06.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
set -euo pipefail
44

55
# TODO: Write a command to output input.txt with one fix:
6+
sed 's/,\([^ ]\)/, \1/g' input.txt
7+
68
# If a comma in input.txt is not followed by a space, add a space after.
79
# If there is already a space after a comma, do not add an additional space.
810
# The output should contain 11 lines.

0 commit comments

Comments
 (0)