Page MenuHomeFreeBSD

Remove an unneeded 'tail -n 1' from a pipeline
ClosedPublic

Authored by lidl on Mar 4 2019, 2:44 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 20, 10:39 PM
Unknown Object (File)
Thu, Nov 20, 10:31 PM
Unknown Object (File)
Thu, Nov 20, 10:29 PM
Unknown Object (File)
Thu, Nov 20, 10:23 PM
Unknown Object (File)
Thu, Nov 6, 1:45 AM
Unknown Object (File)
Mon, Oct 27, 6:01 AM
Unknown Object (File)
Oct 24 2025, 3:13 AM
Unknown Object (File)
Oct 24 2025, 3:13 AM

Details

Summary

When piping to awk, it's almost always an anti-pattern to use 'grep' first.

When not in a pipeline, sometimes it is faster to use tail, as awk must process all the lines, and won't 'seek'. In a pipeline, both must process all lines, so we might as well skip the extra process creation and just use awk for all the processing.

Test Plan

Verify that the output between:

zpool list -v $rootdev | tail -n 1 | awk '{print $1}'

and

zpool list -v $rootdev | awk 'END {print $1}'

Are the same on all my systems. The output is the same.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 22863