From f9d55836a44e30e8aaba2e89ab838f6ab50c0f35 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 13 Jun 2018 12:31:24 +1000 Subject: [PATCH] docs: update --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index d0d1787..1880afc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ list, send a pull request! * [Get the current date using `strftime`.](#get-the-current-date-using-strftime) * [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) +* [Get the number of lines in a file.](#get-the-number-of-lines-in-a-file) * [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) @@ -93,6 +94,20 @@ tail() { } ``` +## Get the number of lines in a file. + +Alternative to `wc -l`. + +**NOTE:** Requires `bash` 4+ + +```sh +lines() { + # Usage lines "file" + mapfile -tn 0 lines < "$1" + printf '%s\n' "${#lines[@]}" +} +``` + ## Get the directory name of a file path. Alternative to the `dirname` command.