logo

utils-extra

Collection of extra tools for Unixes
commit: d4938e8c26569a0b2ffe8a33b29c6637eb691650
parent 833f3bf5e168a369a5ef4d0c66dcac7416acc8e4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 12 Oct 2023 07:26:42 +0200

sh/wordsort: New

Diffstat:

MMakefile2+-
Mconfigure4++--
Ash-man/wordsort.125+++++++++++++++++++++++++
Ash/wordsort8++++++++
4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,7 @@ check: all .PHONY: lint lint: - $(SHELLCHECK) ./configure test_functions.sh + $(SHELLCHECK) ./configure test_functions.sh ./sh/* SHELLCHECK=${SHELLCHECK} ./test-cmd/shellcheck ${FLAWFINDER} --error-level=4 . $(MANDOC) -Tlint -Wunsupp,error,warning $(MAN1) diff --git a/configure b/configure @@ -57,11 +57,11 @@ pkg_config_check() { gen_targets() { printf 'EXE = ' - printf '%s\n ' cmd/*.c | sed 's;.c$;;' | tr -d '\n' + printf '%s\n ' cmd/*.c sh/* | sed -e 's;.c$;;' | tr -d '\n' echo printf 'MAN1 = ' - printf '%s\n ' cmd/*.1 | tr -d '\n' + printf '%s\n ' cmd/*.1 sh-man/*.1 | tr -d '\n' echo } diff --git a/sh-man/wordsort.1 b/sh-man/wordsort.1 @@ -0,0 +1,25 @@ +.\" utils-extra: Collection of extra tools for Unixes +.\" Copyright 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +.\" SPDX-License-Identifier: MPL-2.0 +.Dd 2023-06-05 +.Dt WORDSORT 1 +.Os +.Sh NAME +.Nm wordsort +.Nd sort each space-separated word into a single line +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility reads stdin; strips newlines; replaces spaces with NULL bytes; passes +.Fl z +and options given to +.Nm +to +.Xr sort 1 +then replaces NULL bytes back to spaces. +.Sh EXIT STATUS +.Ex -std +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact@hacktivis.me diff --git a/sh/wordsort b/sh/wordsort @@ -0,0 +1,8 @@ +#!/bin/sh +# utils-extra: Collection of extra tools for Unixes +# SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +# Uses -z on sort(1), present in GNU, FreeBSD, OpenBSD, BusyBox ; absent in NetBSD +# Any options are passed to sort(1) +tr -d '\n' | tr ' ' '\000' | sort -z "$@" | tr '\000' ' '