From 2e841bb0454c9c3e476dede9b1ea502b615d6873 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 13 Jun 2018 12:21:50 +1000 Subject: [PATCH] docs: update --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 2d1ace2..383b4ac 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ list, send a pull request! * [Get the directory name of a file path.](#get-the-directory-name-of-a-file-path) * [Convert a hex color to RGB](#convert-a-hex-color-to-rgb) * [Convert an RGB color to hex.](#convert-an-rgb-color-to-hex) +* [Trim quotes from a string.](#trim-quotes-from-a-string) +* [Get the first N lines in a file.](#get-the-first-n-lines-in-a-file) +* [Get the last N lines in a file.](#get-the-last-n-lines-in-a-file) @@ -94,4 +97,41 @@ rgb_to_hex() { } ``` +## Trim quotes from a string. +```sh +trim_quotes() { + # Usage: trim_quotes "string" + : "${1//\'}" + printf "%s\\n" "${_//\"}" +} +``` + + +## Get the first N lines in a file. + +Alternative to the `head` command. + +**NOTE:** Requires `bash` 4+ + +```sh +head() { + # Usage: head "n" "file" + mapfile -tn "$1" line < "$2" + printf '%s\n' "${line[@]}" +} +``` + +## Get the last N lines in a file. + +Alternative to the `tail` command. + +**NOTE:** Requires `bash` 4+ + +```sh +tail() { + # Usage: tail "n" "file" + mapfile -tn 0 line < "$2" + printf '%s\n' "${line[@]: -$1}" +} +```