Skip to content

Commit

Permalink
added a1 skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
lancemathias committed Jan 22, 2022
1 parent 1cdd26f commit 5b3ca08
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion labs/a1.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ The `LIST` can either be something like a directory with multiple files or a fil
## Useful Commands
Some commands which could be useful in completing the lab. Of course, there are many approaches to the problems, and using these commands is not required.

### `cat`

`cat` [prints][8] files to the [standard output][7]. Very useful for printing something to pipe into other commands!

### `cut`

`cut [options] [filename]` extracts certain parts of a file (or piped-in input) based on the [arguments][3] that are used. A few which might be useful:
Expand All @@ -106,6 +110,16 @@ Some commands which could be useful in completing the lab. Of course, there are

`grep [pattern] [filename]` [filters out][4] and returns lines from a file (or piped-in input) that contain the specified pattern.

### `sed`

`sed` can do [many things][9], such as editing strings and matching regex. We can use `sed` to replace one pattern with another pattern as follows:

``` sed 's/<PATTERN-TO-REPLACE>/<NEW-PATTERN>/g <INPUT>' ```

sed` can also take piped-in input from something else instead of an explicit input.

The `g` at the end tells `sed` to replace all ocurrences of the pattern; it can be omitted if we want to replace only the first ocurrence of a pattern, or replaced with a number to replace only a certain number of occurrences.

### `xargs`

`xargs` lets us apply a command to an output redirected from a pipe. For instance, `output | xargs command` would apply `command` to `output`. Some useful [options][5]:
Expand Down Expand Up @@ -195,6 +209,8 @@ $ ls -lAh tmp | grep .txt | wc -l # Gets the number of lines in ls which contain
26
```

**Hint:** Need help looping through files? See this week's participation assignment on [Gradescope][10] for more hints on `for` loops!

for bonus points, instead of using something like `sed` to affect the rename,
use [shell parameter expansion][1].

Expand Down Expand Up @@ -238,7 +254,9 @@ $ ls
```

**Hints:**
- If it's easier, download the above file and work on it in your VM so you don't have to process output from `wget`.
- What common text manipulation commands can help you solve this?
- Consider the commands `cat | grep ___ | cut ___ | sed ___ | xargs ___` (though you don't *have to* use them...)
- As always, be aware that there isn't one unique solution to this problem!

Submit your one line solution on Gradescope!
Expand Down Expand Up @@ -307,4 +325,8 @@ You may want to look into `dd`[^dd] and the `iflag=fullblock` argument,
[3]: https://linux.die.net/man/1/cut
[4]: https://linux.die.net/man/1/grep
[5]: https://linux.die.net/man/1/xargs
[6]: https://en.wikipedia.org/wiki/Man_page
[6]: https://en.wikipedia.org/wiki/Man_page
[7]: https://linuxhint.com/bash_stdin_stderr_stdout/
[8]: https://linux.die.net/man/1/cat
[9]: https://linux.die.net/man/1/sed
[10]: https://www.gradescope.com/

0 comments on commit 5b3ca08

Please sign in to comment.