aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2020-01-08 10:24:41 +0100
committerUlrich Müller <ulm@gentoo.org>2020-01-09 09:31:55 +0100
commitc2e9f75dbf89db8e19615dc0b15b05f4d5698584 (patch)
treeaa7bb64f7a3de431b7cf0b8e2bb62a7dac21d270 /tools-reference/head-and-tail
parenttools-reference/head-and-tail: Line counting in tail starts at 1. (diff)
downloaddevmanual-c2e9f75dbf89db8e19615dc0b15b05f4d5698584.tar.gz
devmanual-c2e9f75dbf89db8e19615dc0b15b05f4d5698584.tar.bz2
devmanual-c2e9f75dbf89db8e19615dc0b15b05f4d5698584.zip
tools-reference/head-and-tail: Add another example for tail.
The bad example is taken from the script referenced in bug 536654. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
Diffstat (limited to 'tools-reference/head-and-tail')
-rw-r--r--tools-reference/head-and-tail/text.xml8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools-reference/head-and-tail/text.xml b/tools-reference/head-and-tail/text.xml
index e2b7553..06f17de 100644
--- a/tools-reference/head-and-tail/text.xml
+++ b/tools-reference/head-and-tail/text.xml
@@ -36,6 +36,14 @@ To specify "the last five lines", use <c>tail -n5</c>. To specify "all
but the first five lines", use <c>tail -n+6</c>.
</p>
+<codesample lang="ebuild">
+# bad: drop first five lines, clumsily computing line count
+tail -n $(($(wc -l in.txt | awk '{print $1}') - 5)) in.txt &gt; out.txt
+
+# good: let tail count lines from the beginning of the file
+tail -n +6 in.txt &gt; out.txt
+</codesample>
+
<warning>
<c>head/tail -5</c> syntax is deprecated and not POSIX compliant.
</warning>