
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Contents
nws
is a Unix CLI that normalizes whitespace in text, offering several modes,
grouped into two categories:
Line endings can be changed to be Windows- or Unix-specific, and select
Unicode whitespace and punctuation can be replaced with their closest ASCII
equivalents.
Trims leading and trailing runs of any mix of tabs and spaces and replaces
them with a single space each. The individual modes in this category differ
only with respect to how multi-line input is treated.
Input can be provided either via filename arguments or via stdin.
Option -i
offers in-place updating.
See the examples below, get concise usage information further below, or read the manual.
# Converts a CRLF line-endings file (Windows) to a LF-only file (Unix).
# No output is produced, because the file is updated in-place; a backup
# of the original file is created with suffix '.bak'.
$ nws --mode lf --in-place=.bak from-windows.txt
# Converts a LF-only file (Unix) to a CRLF line-endings file (Windows).
# No output is produced, because the file is updated in-place; since no
# backup suffix is specified, no backup file is created.
$ nws --crlf -i from-unix.txt
# Converts select Unicode whitespace and punctuation chars. to their
# closest ASCII equivalents and sends the output to a different file.
# Note that any other non-ASCII characters are left untouched.
# Helpful for converting code samples that were formatted for display back to
# valid source code.
# IMPORTANT: This only works with properly encoded UTF-8 files.
$ nws --ascii unicode-punct.txt > ascii-punct.txt
cat -et
to better illustrate the output; cat -et
shows line endings as $
(and control chars. as ^M<char>
; e.g., a tab would show as ^I
).# -- Single-input-line normalization (mode option doesn't apply).
> nws <<<' I will be normalized. ' | cat -et
I will be normalized.$
# Ditto, but with a mix of spaces and tabs.
> nws "$(printf ' I \t\t will be normalized.\t\t')" | cat -et
I will be normalized.$
# -- Multi-input-line normalizations, using different modes.
# Create demo file.
> cat <<EOF > /tmp/nws-demo
$(printf '\t')
one
two
$(printf '\t')
three
EOF
# Multi-paragraph mode - by default, or with `--mp` or `-m mp` or
# `--mode multi-para`.
# In addition to line-internal normalization,
# folds runs of blank/empty lines into 1 empty line each.
$ nws < /tmp/nws-demo | cat -et
$
one$
two$
$
three$
$
# Single-paragraph mode: `--sp` or `-m sp` or `--mode single-para`
# In addition to line-internal normalization,
# removes all blank/empty lines.
$ nws --sp < /tmp/nws-demo | cat -et
one$
two$
three$
# Flattened-multi-pargraph mode: `--fp` or `-m fp` or `--mode flat-para`
# In addition to line-internal normalization,
# joins paragraph-internal lines with a space each.
$ nws --fp < /tmp/nws-demo | cat -et
$
one two$
$
three$
$
# Single-output-line mode: `sl` or `-m sl` or `--mode single-line`.
# In addition to line-internal normalization,
# joins all non-empty/non-blank lines with a space each
# to form a single, long output line.
$ nws --sl < /tmp/nws-demo | cat -et
one two three$
Supported platforms
Note: Even if you don't use Node.js, its package manager, npm
, works across platforms and is easy to install; try curl -L http://git.io/n-install | bash
With Node.js or io.js installed, install the package as follows:
[sudo] npm install nws-cli -g
Note:
sudo
depends on how you installed Node.js / io.js and whether you've changed permissions later; if you get an EACCES
error, try again with sudo
.-g
ensures global installation and is needed to put nws
in your system's $PATH
.nws
.chmod +x nws
.$PATH
, such as /usr/local/bin
(OSX) or /usr/bin
(Linux).Find concise usage information below; for complete documentation, read the manual online or,
once installed, run man nws
(nws --man
if installed manually).
$ nws --help
Normalizes whitespace in one of several modes.
nws [-m <mode>] [[-i[<ext>]] file...]
Condensing <mode>s:
All these modes normalize runs of tabs and spaces to a single space
each and trim leading and trailing runs; they only differ with respect to
how multi-line input is processed.
mp (default) multi-paragraph: folds multiple blank lines into one
fp flattened multi-paragraph: normalizes each paragraph to single line
sp single-paragraph: removes all blank lines.
sl single-line: normalizes to single output line
Transliteration <mode>s:
lf translates line endings to LF-only (\n)
crlf translates line endings to CRLF (\r\n)
ascii translates Unicode whitespace and punctuation to ASCII
Alternatively, specify mode values directly as options; e.g., --sp in lieu
of -m sp
Standard options: --help, --man, --version, --home
Copyright (c) 2015-2017 Michael Klement mklement0@gmail.com (http://same2u.net), released under the MIT license.
This project gratefully depends on the following open-source components, according to the terms of their respective licenses.
npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D)
denotes a development-time-only dependency, (O)
an optional dependency, and (P)
a peer dependency.
Versioning complies with semantic versioning (semver).
v0.3.4 (2017-09-06):
--mode ascii
(--asci
) only works with properly encoded UTF-8 files.v0.3.3 (2017-09-05):
xargs
-mediated invocations to at least provide a hint that only
a given batch failed.v0.3.2 (2016-12-11):
--crlf
is now idempotent with input that is already CRLF-
terminated (previously, an extra CR was mistakenly added).v0.3.1 (2016-12-10):
v0.3.0 (2016-11-13):
nws
is now file-based: operands are interpreted as
filenames, and option -i
allows in-place updating. Use stdin to provide
strings as input, such as via echo ... | nws ...
.v0.2.0 (2015-09-18):
-m
); mode names come in both
short and long forms; similarly, --mode
is now supported as a verbose
alternative to -m
.nws
now has a man page (if manually installed, use nws --man
);
nws -h
now just prints concise usage information.v0.1.4 (2015-09-15):
v0.1.3 (2015-06-13):
v0.1.2 (2015-06-13):
v0.1.1 (2015-06-13):
v0.1.0 (2015-06-13):
FAQs
Unix CLI that normalizes whitespace in text.
We found that nws-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.