From 67d9bf06688e34fd791acc327147c933340f4859 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 19 Sep 2019 11:30:09 +0300 Subject: [PATCH] docs: update --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index def46dd..50a085b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ A collection of pure POSIX `sh` alternatives to external processes * [Check if string ends with sub-string](#check-if-string-ends-with-sub-string) * [FILES](#files) * [Get the first N lines of a file](#get-the-first-n-lines-of-a-file) + * [Get the number of lines in a file](#get-the-number-of-lines-in-a-file) @@ -177,3 +178,30 @@ PS1='➜ ' $ head 1 ~/.bashrc # Prompt ``` + +## Get the number of lines in a file + +Alternative to `wc -l`. + +**Example Function:** + +```sh +lines() { + # Usage: lines "file" + while read -r _; do + lines=$((lines+1)) + done < "$1" + + printf '%s\n' "$lines" +} +``` + +**Example Usage:** + +```shell +$ lines ~/.bashrc +48 + +$ lines_loop ~/.bashrc +48 +```