|
| 1 | +[](https://npmjs.com/package/print-nonascii)[](https://github.com/mklement0/print-nonascii/blob/master/LICENSE.md) |
| 2 | + |
| 3 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 4 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 5 | + |
| 6 | +**Contents** |
| 7 | + |
| 8 | +- [print-nonascii: print lines that contain non-ASCII characters.](#print-nonascii-print-lines-that-contain-non-ascii-characters) |
| 9 | +- [Examples](#examples) |
| 10 | +- [Installation](#installation) |
| 11 | + - [Prerequisites](#prerequisites) |
| 12 | + - [Installation from the npm registry](#installation-from-the-npm-registry) |
| 13 | + - [Manual installation](#manual-installation) |
| 14 | +- [Usage](#usage) |
| 15 | +- [License](#license) |
| 16 | + - [Acknowledgements](#acknowledgements) |
| 17 | + - [npm dependencies](#npm-dependencies) |
| 18 | +- [Changelog](#changelog) |
| 19 | + |
| 20 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 21 | + |
| 22 | +# print-nonascii: print lines that contain non-ASCII characters. |
| 23 | + |
| 24 | +`print-nonascii` is a Unix CLI that locates lines in text files or |
| 25 | +stdin input that contain non-ASCII characters, which is helpful when |
| 26 | +diagnosing character encoding problems. |
| 27 | + |
| 28 | +Lines can be printed as-is and/or using abstract representations of non-ASCII |
| 29 | +characters in one of several formats; namely: |
| 30 | + |
| 31 | +* `-v`, `--caret` ... the same representation `cat -v` uses, based on caret notation. |
| 32 | +* `--bash` ... per-_byte_ two-digit hex. escape sequences such as `\xc3` |
| 33 | +* `--psh` ... PowerShell Unicode escape sequences such as `` `u{20ac} `` for `€` |
| 34 | + |
| 35 | +Note: `--psh` only works correctly with properly UTF-8-encoded input. |
| 36 | + |
| 37 | +Line numbers can be prepended on request, and output for multiple input |
| 38 | +files is by default preceded with headers identifying each input file. |
| 39 | + |
| 40 | +_Caveat: For now, no automated tests are run before releases._ |
| 41 | + |
| 42 | +# Examples |
| 43 | + |
| 44 | +```sh |
| 45 | +# Create a test file with 1 line containing a non-ASCII character. |
| 46 | +$ cat <<'EOF' > /tmp/test.txt |
| 47 | +one |
| 48 | +twö |
| 49 | +three |
| 50 | +EOF |
| 51 | + |
| 52 | +# Print only lines that have non-ASCII characters, as-is. |
| 53 | +$ print-nonascii /tmp/test.txt |
| 54 | +twö |
| 55 | + |
| 56 | +# Print only lines that have non-ASCII characters, with line numbers: |
| 57 | +$ print-nonascii -n /tmp/test.txt |
| 58 | +2:twö |
| 59 | + |
| 60 | +# Print only lines that have non-ASCII characters, using PowerShell |
| 61 | +# Unicode escape-sequence notation (--psh), preceded by the line as-is (--raw). |
| 62 | +# The Unicode code point of character "ö" is U+00F6: |
| 63 | +$ print-nonascii --psh --raw /tmp/test.txt |
| 64 | +twö |
| 65 | +tw`u{f6} |
| 66 | +
|
| 67 | +# Ditto with line numbers and per-byte Bash escape sequences: |
| 68 | +$ print-nonascii --bash --raw /tmp/test.txt |
| 69 | +twö |
| 70 | +tw\xc3\xb6 |
| 71 | +
|
| 72 | +# Simulate input from multiple files by specifying the same file twice, so as |
| 73 | +# to show the headers identifying each input file (suppress with -b). |
| 74 | +# Note that each header line (invisibly) starts with control character U+0001, |
| 75 | +# so as to allow more predictable identification of header lines in the output. |
| 76 | +$ print-nonascii -n /tmp/test.txt /tmp/test.txt |
| 77 | +### /tmp/test.txt |
| 78 | +2:twö |
| 79 | +### /tmp/test.txt |
| 80 | +2:twö |
| 81 | +``` |
| 82 | + |
| 83 | +# Installation |
| 84 | + |
| 85 | +## Prerequisites |
| 86 | + |
| 87 | +* When installing from the **npm registry**: **macOS** and **Linux** |
| 88 | +* When installing **manually**: any Unix platform with `bash` that also has `perl` installed. |
| 89 | + |
| 90 | +## Installation from the npm registry |
| 91 | + |
| 92 | +With [Node.js](http://nodejs.org/) installed, install [the package](https://www.npmjs.com/package/print-nonascii) as follows: |
| 93 | + |
| 94 | + [sudo] npm install print-nonascii -g |
| 95 | + |
| 96 | +**Note**: |
| 97 | + |
| 98 | +<sup>Note: Even if you don't use Node.js, its package manager, `npm`, works across platforms and is easy to install; try [`curl -L https://git.io/n-install | bash`](https://github.com/mklement0/n-install)</sup> |
| 99 | +
|
| 100 | +* Whether you need `sudo` depends on how you installed Node.js / io.js and whether you've [changed permissions later](https://docs.npmjs.com/getting-started/fixing-npm-permissions); if you get an `EACCES` error, try again with `sudo`. |
| 101 | +* The `-g` ensures [_global_ installation](https://docs.npmjs.com/getting-started/installing-npm-packages-globally) and is needed to put `print-nonascii` in your system's `$PATH`. |
| 102 | +
|
| 103 | +## Manual installation |
| 104 | +
|
| 105 | +* Download [the CLI](https://raw.githubusercontent.com/mklement0/print-nonascii/stable/bin/print-nonascii) as `print-nonascii`. |
| 106 | +* Make it executable with `chmod +x print-nonascii`. |
| 107 | +* Move it or symlink it to a folder in your `$PATH`, such as `/usr/local/bin` (macOS) or `/usr/bin` (Linux). |
| 108 | +
|
| 109 | +# Usage |
| 110 | +
|
| 111 | +Find concise usage information below; for complete documentation, read the [manual online](doc/print-nonascii.md), or, once installed, run `man print-nonascii` (`print-nonascii --man` if installed manually). |
| 112 | +
|
| 113 | +<!-- DO NOT EDIT THE FENCED CODE BLOCK and RETAIN THIS COMMENT: The fenced code block below is updated by `make update-readme/release` with CLI usage information. --> |
| 114 | +
|
| 115 | +```nohighlight |
| 116 | +$ print-nonascii --help |
| 117 | +
|
| 118 | +
|
| 119 | +Prints lines that contain non-ASCII characters. |
| 120 | +
|
| 121 | + print-nonascii [--<mode> [-r]] [-n] [-b] [file ...] |
| 122 | + print-nonascii -q [file ...] |
| 123 | +
|
| 124 | + --<mode> prints abstract representations of non-ASCII chars.; one of: |
| 125 | + --caret, -v ... use caret notation, as cat -v would. |
| 126 | + --bash ... represent non-ASCII bytes as \xhh |
| 127 | + --psh ... (PowerShell) represent non-ASCII Unicode characters as |
| 128 | + Unicode escape sequences: <backtick>u{h+} |
| 129 | + |
| 130 | + -r, --raw ... with --<mode>, print each matching line as-is too, first. |
| 131 | +
|
| 132 | + -n, --line-number ... prefix the output lines with their line number from |
| 133 | + the original file, using format "<line-number>:" - decimal line numbers, |
| 134 | + no padding, no space before or after the ":" |
| 135 | +
|
| 136 | + -b, --bare ... suppress per-input-filename headers |
| 137 | +
|
| 138 | + -q ... quiet mode: produce no output; signal presence of non-ASCII chars. |
| 139 | + with exit code 0; exit code 100 signals that there are none. |
| 140 | +
|
| 141 | +Standard options: --help, --man, --version, --home |
| 142 | +``` |
| 143 | +
|
| 144 | +<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'LICENSE.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. --> |
| 145 | +
|
| 146 | +# License |
| 147 | +
|
| 148 | +Copyright (c) 2017 Michael Klement <[email protected]> (http://same2u.net), released under the [MIT license](https://spdx.org/licenses/MIT#licenseText). |
| 149 | +
|
| 150 | +## Acknowledgements |
| 151 | +
|
| 152 | +This project gratefully depends on the following open-source components, according to the terms of their respective licenses. |
| 153 | +
|
| 154 | +[npm](https://www.npmjs.com/) dependencies below have an optional suffix 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. |
| 155 | +
|
| 156 | +<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the dependencies from 'package.json'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. --> |
| 157 | +
|
| 158 | +## npm dependencies |
| 159 | +
|
| 160 | +* [doctoc (D)](https://github.com/thlorenz/doctoc#readme) |
| 161 | +* [json (D)](https://github.com/trentm/json#readme) |
| 162 | +* [marked-man (D)](https://github.com/kapouer/marked-man#readme) |
| 163 | +* [replace (D)](https://github.com/harthur/replace#readme) |
| 164 | +* [semver (D)](https://github.com/npm/node-semver#readme) |
| 165 | +* [urchin (D)](https://github.com/tlevine/urchin#readme) |
| 166 | +
|
| 167 | +<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'CHANGELOG.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. --> |
| 168 | +
|
| 169 | +# Changelog |
| 170 | +
|
| 171 | +Versioning complies with [semantic versioning (semver)](http://semver.org/). |
| 172 | +
|
| 173 | +<!-- RETAIN THIS COMMENT. An entry template for a new version is automatically added each time `make version` is called. Fill in changes afterward. --> |
| 174 | +
|
| 175 | +* **v0.0.1** (2017-09-10): |
| 176 | + * Initial release. |
0 commit comments