forked from jarv/cmdchallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenges.yaml
484 lines (477 loc) · 19.5 KB
/
challenges.yaml
1
2
3
4
5
6
7
8
9
10
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
---
# slug: name of the challenge (required)
# description: describe teh challenge (required)
# example: solution for the challenge (required)
# expected_output:
# lines: lines returned from the command, as an array (required)
# order: whether or not order matters (optional, default is true)
# re_sub: regex substitution on the output lines (optional)
# regex: lines are regular expressions (optional)
# tests: tests to run after the command completes
# version: if the challenge is modified this number should be bumped
# refresh the cache.
# author: Add a field for contributions.
########## START BEGINNER
- slug: hello_world
version: 1
author: cmdchallenge
description: |
Print "hello world".
Hint: There are many ways to print text on
the command line, one way is with the 'echo'
command.
Try it below and good luck!
example: echo 'hello world'
expected_output:
lines:
- 'hello world'
- slug: current_working_directory
version: 1
author: cmdchallenge
description: |
Print the current working directory.
example: pwd
expected_output:
lines:
- '/var/challenges/current_working_directory'
- slug: list_files
version: 1
author: cmdchallenge
description: |
List all of the files in the current
directory, one file per line.
example: ls
expected_output:
lines:
- 'README'
- slug: print_file_contents
version: 1
author: cmdchallenge
description: |
There is a file named "access.log" in the
current directory. Print the contents.
example: cat access.log
expected_output:
lines:
- 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
- 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- slug: last_lines
version: 1
author: cmdchallenge
disp_title: Last lines in a file.
description: |
Print the last 5 lines of "access.log".
example: tail -n 5 access.log
expected_output:
lines:
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- slug: find_string_in_a_file
version: 1
author: cmdchallenge
description: |
There is a file named "access.log" in the
current working directory. Print all lines
in this file that contains the string "GET".
example: grep 'GET' access.log
expected_output:
lines:
- 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
- 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- slug: find_tabs_in_a_file
version: 1
author: cmdchallenge
description: How many lines contain a tab in the file README
example: grep -P '\t' file-with-tabs.txt | wc -l
expected_output:
lines:
- 3
- slug: search_for_files_containing_string
version: 1
author: cmdchallenge
description: |
Print all files, one per line (not the path, just the file)
that contain the string "500".
example: grep -l 500 *
expected_output:
order: false
lines:
- README
- access.log
- access.log.1
- slug: search_for_files_by_extension
version: 1
author: cmdchallenge
description: |
Print the relative file paths, one path
per line for all filenames that start with
"access.log" in the current directory.
example: find . -name 'access.log*'
expected_output:
order: false
re_sub: ['^\./', '']
lines:
- 'access.log'
- 'access.log.1'
- 'access.log.2'
- slug: search_for_string_in_files_recursive
version: 1
author: cmdchallenge
description: |
Print all matching lines (without the filename
or the file path) in all files under the current
directory that start with "access.log" that
contain the string "500". Note that there are no
files named "access.log" in the current directory,
you will need to search recursively.
example: grep -h 500 **/access.log*
expected_output:
order: false
lines:
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
- slug: extract_ip_addresses
version: 1
author: cmdchallenge
description: |
Extract all IP addreses from files
that start with "access.log" printing one
IP address per line.
example: grep -Pho '^\d+\.\d+\.\d+\.\d+' **/access.log*
expected_output:
re_sub: ['^[\w/.]*?:', '']
order: false
lines:
- 163.56.115.58
- 75.113.188.234
- 69.16.40.148
- 225.219.54.140
- 207.243.19.2
- 199.37.62.156
- 55.74.240.123
- 251.111.109.143
- 101.163.230.250
- 200.19.168.148
- 108.68.174.15
- 17.2.20.139
- 28.151.137.59
- 199.150.241.179
- 2.71.250.27
- 17.137.186.194
- 151.84.119.34
- 4.180.204.195
- 9.230.96.54
- 157.143.233.21
- slug: delete_files
version: 1
author: cmdchallenge
description: |
Delete all of the files in this challenge
directory including all subdirectories and
their contents.
tests:
- test: '[[ $(find .) == "." ]]'
msg: Test failed, files or directories remain.
example: find . -delete
- slug: count_files
version: 1
author: cmdchallenge
description: |
Count the number of files in the current
working directory. Print the number of
files as a single integer.
example: ls | wc -l
expected_output:
re_sub: ['^\s+', '']
lines:
- '2'
- slug: simple_sort
version: 1
author: cmdchallenge
disp_title: Sort lines in a file.
description: |
Print the contents of access.log
sorted.
example: sort access.log
expected_output:
lines:
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
- slug: count_string_in_line
version: 1
author: cmdchallenge
disp_title: Count Matching Lines.
description: |
Print the number of lines
in access.log that contain the string
"GET".
example: grep -c "GET" access.log
expected_output:
re_sub: ['^\s+', '']
lines:
- '8'
- slug: split_on_a_char
version: 1
author: cmdchallenge
disp_title: Split on a single character.
description: |
The file split-me.txt contains a list of
numbers separated by a ';' character.
Split the numbers on the ';' character,
one number per line.
example: tr ';' '\n' < split-me.txt
expected_output:
lines: [1,2,3,4,5,6,7,8,9,10]
- slug: print_number_sequence
version: 1
author: cmdchallenge
disp_title: Generate a number sequence.
description: |
Print the numbers 1 to 100 separated
by spaces.
example: echo $(seq 1 100)
expected_output:
lines:
- 1 2 3 4 5 6 7 8 9 10 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
- slug: remove_files_with_a_dash
version: 1
author: cmdchallenge
disp_title: Remove files that start with a dash
description: |
There are some files in this directory that
start with a dash in the filename.
Remove those files.
example: rm ./-*
tests:
- test: '[[ $(find . -type f | wc -l) == 2 ]]'
msg: Test failed, expecting 2 files.
- test: '[[ $(find . -name "-*" | wc -l) == 0 ]]'
msg: Test failed, files with dashes exist
- slug: remove_files_with_extension
version: 1
author: cmdchallenge
disp_title: Remove files with extension.
description: |
There are files in this challenge with
different file extensions.
Remove all files with the .doc extension
recursively in the current working directory.
example: rm **/*.doc
tests:
- test: '[[ $(find . -type f | wc -l) == 5 ]]'
msg: Test failed, expecting 5 files.
- test: '[[ $(find . -name "*.doc" | wc -l) == 0 ]]'
msg: Test failed, expecting 0 files with a .doc extension.
- slug: remove_files_without_extension
version: 1
author: bryfry
disp_title: Remove files without extension.
description: |
There are files in this challenge with
different file extensions.
Remove all files without the .txt and .exe extensions
recursively in the current working directory.
example: find . -type f -regextype posix-extended ! -regex ".*(\.txt|\.exe)$" -exec rm {} +
tests:
- test: '[[ $(find . -type f | wc -l) == 4 ]]'
msg: Test failed, expecting 4 files.
- test: '[[ $(find . -name "*.txt" | wc -l) == 3 ]]'
msg: Test failed, expecting 3 files with a .txt extension.
- test: '[[ $(find . -name "*.exe" | wc -l) == 1 ]]'
msg: Test failed, expecting 1 files with a .exe extension.
########## END BEGINNER
########### START INTERMEDIATE
- slug: replace_text_in_files
version: 1
author: cmdchallenge
disp_title: Replace text in files
example: sed -i 's/challenges are difficult//g' **/*.txt
description: |
This challenge has text files (with a .txt extension)
that contain the phrase "challenges are difficult".
Delete this phrase recursively from all text files.
Note that some files are in subdirectories so you will
need to search for them.
tests:
- test: '[[ $(find . -name "*.txt" | wc -l) == 3 ]]'
msg: Test failed, expecting 3 text files
- test: '[[ $(find . -name "*.txt" -print0 | xargs -0 -n1 grep "challenges are difficult") == "" ]]'
msg: Test failed, found the string "challenges are difficult"
- test: 'grep -q "challenges are difficult" README'
msg: Test failed, files without .txt extension must remain unmodified
- slug: sum_all_numbers
version: 1
author: cmdchallenge
disp_title: Sum numbers in a file.
example: paste -sd+ sum-me.txt | bc
description: |
The file sum-me.txt have a list of numbers,
one per line. Print the sum of these numbers.
expected_output:
lines:
- 42
- slug: just_the_files
version: 1
author: cmdchallenge
disp_title: Print only the filenames
description: |
Print all files in the current directory
recursively without the leading directory path.
example: find -type f -printf '%f\n'
expected_output:
order: false
lines:
- animi.doc
- corporis.xls
- odit.doc
- beatae.flac
- error.doc
- libero.xls
- necessitatibus.doc
- README
- totam
- slug: remove_extensions_from_files
version: 1
author: cmdchallenge
disp_title: Remove file extensions.
description: |
Remove the extension from all files in
the current directory recursively.
example: for f in $(find . -type f -name "*.*"); do mv "$f" "${f%.*}"; done
tests:
- test: '[[ $(find . -type f -name "*.*") == "" ]]'
msg: Test failed, there are still files with extensions in the current directory.
- slug: replace_spaces_in_filenames
version: 1
author: cmdchallenge
disp_title: Replace spaces in file names.
description: |
The files in this challenge contain spaces.
List all of the files (filenames only) in the
current directory but replace all spaces with
a '.' character.
example: ls | tr ' ' '.'
expected_output:
order: false
lines: ['Adam.Simpson', 'Alexis.Stein', 'Allison.Brown', 'Amy.Anderson', 'Angel.Saunders',
'Brad.Michael', 'Briana.Wilson', 'Carrie.Alexander', 'Christine.Valdez', 'Christopher.Miller',
'Claudia.Mccormick', 'Corey.Bird', 'Courtney.Miller', 'Crystal.Dunn', 'Crystal.Valdez',
'Erica.Richardson', 'James.Harper', 'James.Roberts', 'Jared.Hill.DVM', 'John.Nguyen',
'Jorge.Ross', 'Joseph.Hurst', 'Karen.Ramirez', 'Kevin.Price', 'Kimberly.Parker', 'Lori.Macias',
'Luke.Mason', 'Lynn.Robinson', 'Mallory.Peterson', 'Marie.Gutierrez', 'Matthew.Romero',
'Michaela.Hobbs', 'Molly.Stevens', 'Mr..James.Lopez', 'Mr..Shawn.Martin', 'Mrs..Jade.Clark',
'Olivia.Irwin', 'Parker.Gilbert', 'README', 'Robert.Gregory', 'Robert.Hill', 'Sarah.Hill',
'Scott.Rice', 'Sheri.Bishop', 'Tamara.Anderson', 'Tammy.Galloway', 'Terri.Young', 'Thomas.Parks',
'Thomas.Washington', 'Tiffany.Clark', 'Yvonne.Myers']
- slug: files_starting_with_a_number
version: 1
author: cmdchallenge
disp_title: Print files starting with a number.
description: |
There are a mix of files in this directory
that start with letters and numbers. Print
the filenames (just the filenames) of all
files that start with a number recursively
in the current directory.
example: find . -type f -name '[[:digit:]]*' -printf '%f\n'
expected_output:
order: false
lines: ['974Michael Bowman', '540Katherine Jones', '436Teresa Owens', '04Carrie Alexander', '778Holly Archer',
'3maxime.mp3', '682Terri Jones', '511Tammy Welch', '293Linda Bennett', '670James Jacobs', '737Jeffrey Davis',
'42Robert Hill', '25Brandon Mcdonald', '402Nancy Henson', '78Michelle Spencer', '132Rebecca Rubio',
'639Charles Ferguson', '335John Joseph', '99blanditiis.avi', '477Thomas Pierce MD', '757Robert Marquez',
'388Andrew Carter', '48Thomas Allen', '593Brett Martin']
- slug: print_nth_line
version: 1
author: cmdchallenge
disp_title: Print the nth line.
description: |
Print the 25th line of the file faces.txt
example: sed -n '25p' faces.txt
expected_output:
lines: ['¯\_(ツ)_/¯']
- slug: remove_duplicate_lines
version: 1
author: cmdchallenge
disp_time: Remove duplicate lines without sorting
description: |
Print the file faces.txt, but only print the first instance of each
duplicate line, even if the duplicates don't appear next to each other.
Note that order matters so don't sort the lines before removing duplicates.
example: awk '!x[$0]++' faces.txt
expected_output:
lines: ['(◕‿◕)', '(^̮^)', 'ʘ‿ʘ', 'ಠ_ಠ', 'ಠ⌣ಠ', 'ಠ‿ಠ', '(ʘ‿ʘ)', '(ಠ_ಠ)', '¯\_(ツ)_/¯',
'(ಠ⌣ಠ', 'ಠಠ⌣ಠ)', '(ಠ‿ಠ)', '٩◔̯◔۶', 'ヽ༼ຈل͜ຈ༽ノ', '♥‿♥', '◔̯◔', '⊙﹏⊙',
'(¬_¬)', '(;一_一)', '(͡° ͜ʖ ͡°)', '(° ͜ʖ °)', '¯\(°_o)/¯', '( ゚ヮ゚)', '(︺︹︺)']
- slug: corrupted_text
version: 1
author: cmdchallenge
disp_title: Removing extra '!' characters from text
example: perl -pne 's/!(?![ \n])//g;' war_and_peace.txt | perl -pne 's/(?<=[.])!//g' | perl -pne 's/!(?= [a-z])//g'
description: |
The following excerpt from War and Peace is saved to
the file 'war_and_peace.txt':
She is betraying us! Russia alone must save Europe.
Our gracious sovereign recognizes his high vocation
and will be true to it. That is the one thing I have
faith in! Our good and wonderful sovereign has to
perform the noblest role on earth, and he is so virtuous
and noble that God will not forsake him. He will fulfill
his vocation and crush the hydra of revolution, which
has become more terrible than ever in the person of this
murderer and villain!
The file however has been corrupted, there are random '!'
marks inserted throughout. Print the original text.
expected_output:
lines:
- She is betraying us! Russia alone must save Europe.
- Our gracious sovereign recognizes his high vocation
- and will be true to it. That is the one thing I have
- faith in! Our good and wonderful sovereign has to
- perform the noblest role on earth, and he is so virtuous
- and noble that God will not forsake him. He will fulfill
- his vocation and crush the hydra of revolution, which
- has become more terrible than ever in the person of this
- murderer and villain!
- slug: print_common_lines
version: 1
author: amboar
disp_title: Print common lines
order: false
example: "comm -12 <(cut -d' ' -f1 access.log.1 | sort) <(cut -d' ' -f1 access.log.2 | sort)"
description: |
access.log.1 and access.log.2 are http server logs. Print the IP
addresses common to both files, one per line.
expected_output:
lines:
- 108.68.174.15
- 17.137.186.194
- 2.71.250.27
- 28.151.137.59
########### END INTERMEDIATE