index.html (7895B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title>table - Command line utility to format and display CSV</title> 6 <link rel="canonical" href="https://strahinja.srht.site/table/index.html" /> 7 <meta name="description" content="Command line utility to format and display CSV" /> 8 <meta name="viewport" content="width=device-width, initial-scale=1" /> 9 <style> 10 html, body, html * 11 { 12 font-family: "Noto Sans", "Helvetica", "Arial", sans-serif; 13 font-weight: normal; 14 font-size: 11pt; 15 } 16 17 body 18 { 19 display: flex; 20 flex-direction: column; 21 } 22 23 body 24 { 25 max-width: 1024px; 26 margin: 0 auto; 27 } 28 29 @media(prefers-color-scheme: dark) 30 { 31 html, 32 body 33 { 34 color: #fff; 35 background-color: #121212; 36 } 37 38 a, 39 a:link, 40 a:active, 41 a:visited 42 { 43 color: #aaf; 44 } 45 } 46 47 @media(max-width: 1024px) 48 { 49 body 50 { 51 max-width: 100%; 52 margin: 0 1em; 53 } 54 } 55 56 @media(max-width: 960px) 57 { 58 body > * 59 { 60 width: 100%; 61 max-width: initial; 62 } 63 } 64 65 h1, h2, h3, h4, h5 66 { 67 font-weight: bold; 68 } 69 70 h1 71 { 72 font-size: 2.25em; 73 } 74 75 h2 76 { 77 font-size: 1.5em; 78 font-variant: small-caps; 79 } 80 81 h3 82 { 83 font-size: 1.2em; 84 } 85 86 code, pre, pre * 87 { 88 font-family: "Noto Mono", "Courier New", "Courier", monospace; 89 } 90 91 pre 92 { 93 overflow-x: auto; 94 padding: 0 2em; 95 } 96 97 .example 98 { 99 margin-top: .5em; 100 margin-bottom: 1em; 101 } 102 103 .explanation 104 { 105 margin-bottom: .5em; 106 margin-top: 1em; 107 } 108 </style> 109 </head> 110 <body> 111 <h1>table</h1> 112 113 <p>Command line utility to format and display CSV.</p> 114 115 <h2>Prerequisites</h2> 116 117 <p>C compiler, preferably <strong>GNU C</strong> or similar, <a 118 href="https://www.gnu.org/software/libunistring/">GNU 119 libunistring</a>.</p> 120 121 <h2>Install</h2> 122 123 <pre> 124 $ git clone <a 125 href="https://git.sr.ht/~strahinja/table">https://git.sr.ht/~strahinja/table</a> 126 $ cd table 127 $ su 128 </pre> 129 130 <p>Then, if you have <a href="https://github.com/apenwarr/redo">apenwarr/redo</a>:</p> 131 132 <pre> 133 # redo install 134 </pre> 135 136 <p>if you don't:</p> 137 138 <pre> 139 # ./do install 140 </pre> 141 142 <h2>Examples</h2> 143 144 <p class="explanation">Periodically display CPU load information in a 145 single-line table</p> 146 147 <pre class="example"> 148 $ watch "table /proc/loadavg -d ' ' -c 50 -n -s ss"</pre> 149 150 <p class="explanation">Format a long list of files in the current 151 directory in a double line table with single-line column divisors</p> 152 153 <pre class="example"> 154 $ LC_ALL=C ls -l | tail -n +2 | sed -e 's/ \+/ /g' | table -d ' ' -n</pre> 155 156 <p class="explanation">Like the above, but only permissions and file 157 names are printed in a narrow table</p> 158 159 <pre class="example"> 160 $ LC_ALL=C ls -l | tail -n +2 | awk '{ print $1 " " $9 }' | table -d ' ' -c 30 -n</pre> 161 162 <h2>Configuring GNU Midnight Commander (mc)</h2> 163 164 <p><a href="https://www.midnight-commander.org">GNU Midnight 165 Commander</a> file manager can be configured to use table as a 166 viewer (F3) for CSV files. To do that, edit 167 <code>/usr/lib/mc/ext.d/text.sh</code> (or make and edit a local copy, 168 for example in <code>~/bin/text.sh</code>, which we will assume here) so 169 that</p> 170 171 <pre> 172 case "${filetype}" in</pre> 173 174 <p>block in <code>do_view_action()</code> function includes:</p> 175 176 <pre> 177 csv) 178 table -m -n "${MC_EXT_FILENAME}" 179 ;;</pre> 180 181 <p>You also need to edit extension file (Command->Edit extension 182 file) or just edit <code>~/.config/mc/mc.ext</code> and add the 183 lines:</p> 184 185 <pre> 186 shell/.csv 187 View=%view{ascii} ~/bin/text.sh view csv %var{PAGER:more}</pre> 188 189 <p>before includes and default target.</p> 190 191 <h2>Configuring ranger file manager</h2> 192 193 <p><a href="https://github.com/ranger/ranger">Ranger</a> file manager 194 can be configured to use table as a CSV file viewer. To do that, add the 195 following to <code>~/.config/ranger/scope.sh</code>, within the function 196 <code>handle_extension()</code>:</p> 197 198 <pre> 199 ## CSV 200 csv) 201 table -m "${FILE_PATH}" && exit 5 202 exit 1;;</pre> 203 204 <h2>Configuring vifm</h2> 205 206 <p><a href="https://vifm.info">Vifm</a> file manager can also be 207 configured to use table as a CSV file viewer. To accomplish this, add 208 the following lines to <code>~/.config/vifm/vifmrc</code>: 209 210 <pre> 211 " CSV 212 fileviewer *.csv 213 \ table -m %c</pre> 214 215 216 <h2>Changelog</h2> 217 218 <h3>v0.2.2</h3> 219 <ul> 220 <li>Optimizations and bugfixes</li> 221 <li>Added description how to configure table as a viewer for GNU MC</li> 222 <li>Added the --msdos option</li> 223 <li>Changed URLs to sourcehut</li> 224 </ul> 225 226 <h3>v0.2.1</h3> 227 <ul> 228 <li>Added format support</li> 229 </ul> 230 231 <h3>v0.2</h3> 232 <ul> 233 <li>Switched to apenwarr/redo</li> 234 <li>Core code rewrite. Prevented leaks with valgrind</li> 235 <li>New examples directory, updated scripts in tests</li> 236 <li>Updated manpage</li> 237 </ul> 238 239 <h3>v0.1.2-beta</h3> 240 <ul> 241 <li>Add --border-mode</li> 242 <li>Fix last row in ls -mw30 | table when last input line has only 243 one column</li> 244 </ul> 245 246 <h3>v0.1.1-beta</h3> 247 <ul> 248 <li>Ignore malformed UTF-8 sequences. Segmentation faulted 249 (test/who-Huw.sh with LC_ALL=sr_RS.UTF8 and cyrillic user 250 names)</li> 251 <li>Use "T" connector chars; connector selection similar to -s</li> 252 </ul> 253 254 <h3>v0.1-alpha</h3> 255 <ul> 256 <li>Read and display columns</li> 257 <li>Handle tabs - unwrap to spaces at tab stops 258 (test/lsb_release.sh)</li> 259 <li>Better UTF-8 substring code based on screen columns</li> 260 </ul> 261 262 <h2>License</h2> 263 264 <p>table - Command line utility to format and display CSV.<br /> 265 Copyright (C) 2020, 2021 Страхиња Радић</p> 266 267 <p>This program is free software: you can redistribute it and/or modify 268 it under the terms of the GNU General Public License as published by the 269 Free Software Foundation, either version 3 of the License, or (at your 270 option) any later version.</p> 271 272 <p>This program is distributed in the hope that it will be useful, but 273 WITHOUT ANY WARRANTY; without even the implied warranty of 274 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 275 Public License for more details.</p> 276 277 <p>You should have received a copy of the GNU General Public License 278 along with this program. If not, see <a 279 href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.</p> 280 </body> 281 </html> 282