Hot answers tagged

171 votes
Accepted

Creating diagrams in ASCII

asciio I've used asciio for several years. Many of the diagrams on this site I've created using asciio. example vncviewer .-,( ),-. __ _ .-( )-. ...
user avatar
  • 346k
72 votes
Accepted

What is the ^M character called?

It is known as carriage return. If you're using vim you can enter insert mode and type CTRL-v CTRL-m. That ^M is the keyboard equivalent to \r. Inserting 0x0D in a hex editor will do the task. ...
user avatar
  • 36.8k
51 votes

Does vi silently add a newline (LF) at the end of file?

POSIX requires this behavior, so it's not in any way unusual. From the POSIX vi manual: INPUT FILES See the INPUT FILES section of the ex command for a description of the input files supported by the ...
user avatar
  • 1,836
44 votes

Converting a UTF-8 file to ASCII (best-effort)

This will work for some things: iconv -f utf-8 -t ascii//TRANSLIT echo ĥéĺłœ π | iconv -f utf-8 -t ascii//TRANSLIT returns helloe ?. Any characters that iconv doesn’t know how to convert will be ...
user avatar
34 votes
Accepted

Is there a convenient way to classify files as "binary" or "text"?

If you ask file for just the mime-type you'll get many different ones like text/x-shellscript, and application/x-executable etc, but I imagine if you just check for the "text" part you should get good ...
user avatar
  • 45.3k
33 votes

Creating diagrams in ASCII

Have a look at artist-mode or picture-mode for Emacs (see also this screencast). You might also want to check out ditaa.
user avatar
  • 3,345
32 votes
Accepted

Does vi silently add a newline (LF) at the end of file?

This is the expected vi behavior. Your file has an incomplete last line so strictly speaking (i.e. according to the POSIX standard), it is not a text file but a binary file. vi which is a text file ...
user avatar
  • 58.2k
30 votes
Accepted

What conditions must be met for a file to be a text file as defined by POSIX?

Must a text file be a regular file? In the above excerpt it does not explicitly say the file must be a regular file No; the excerpt even specifically notes standard input as a potential text file. ...
user avatar
29 votes

Creating diagrams in ASCII

I found another answer; I am not sure it is fully usable, but remember that GNU roff (groff) has a processor for the Pic language as well as an ascii postprocessor; thus you may have a try at ...
user avatar
28 votes
Accepted

How does the file command distinguish text and LaTeX files?

The file type recognition is driven by so-called magic patterns. The magic file for analyzing TeX family source code contains a number of macro names that cause a file to be classified as LaTeX. Each ...
user avatar
  • 1,602
26 votes

Is there a convenient way to classify files as "binary" or "text"?

Another approach would be to use isutf8 from the moreutils collection. It exits with 0 if the file is valid UTF-8 or ASCII, or short circuits, prints an error message (silence with -q) and exits with ...
user avatar
23 votes

Creating diagrams in ASCII

Maybe you will be interested in graph-easy. Example: echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy produces: +--------+ car +-----+ | Bonn | -----> | Ulm | +...
user avatar
20 votes

Open a text file in a terminal and auto-refresh it whenever it is changed

tail -f /var/log/syslog Shows the syslog updates as they are added to the file.
user avatar
  • 201
18 votes
Accepted

Converting a UTF-8 file to ASCII (best-effort)

konwert utf8-ascii It will do best-effort conversion, depending on the conversion tables. If you know approximately the input language, there are language specific filters giving better results, e.g. ...
user avatar
18 votes

Is there a convenient way to classify files as "binary" or "text"?

If you like the heuristic used by GNU grep, you could use it: isbinary() { LC_MESSAGES=C grep -Hm1 '^' < "${1-$REPLY}" | grep -q '^Binary' } It searches for NUL bytes in the first buffer read ...
user avatar
17 votes
Accepted

What does $0=$1 mean in awk?

It's not really $0=$1; think of it more like $0 = ($1" "$1*$2" "$3*$4) So $0=$1" "$1*$2" "$3*$4 assigns the result of string concatenation $1" "$1*$2" "$3*$4 to variable $0 and performs the ...
user avatar
  • 72.4k
15 votes
Accepted

Filter output of command by color

Switching the color is done through escape sequences embedded in the text. Invariably, programs issue ANSI escape sequences, because that's what virtually all terminals support nowadays. The escape ...
user avatar
15 votes

Why does this grep statement do the opposite of what I expect?

From GNU grep manual: \< Match the empty string at the beginning of word. \> Match the empty string at the end of word. This is also relevant [emphasis mine]: -w --word-regexp Select only ...
user avatar
15 votes
Accepted

How to search for multiline text files containing a set of words (e.g., AAA & (BBB | CCC) & ~DD)?

Your solution is pretty legible for the task, in my opinion. However, it's slow, because it spawns 3 processes per file. I reckon Awk is better suited here because it will allow to read a whole batch ...
user avatar
  • 17.4k
14 votes

Possible to view two text files side by side (read only)?

The less command by itself cannot do any diff'ing. You can use the diff -y command to show the diff of 2 files side-by-side and then pipe that into less however. Method #1 - using diff + less This ...
user avatar
  • 346k
13 votes

Existing command line text on screen to file? (non-graphical Linux)

Did you consider the screendump command?
user avatar
  • 8,596
12 votes

Finding all "Non-Binary" files

The accepted answer didn't find all of them for me. Here is an example using grep's -I to ignore binaries, and ignoring all hidden files... find . -type f -not -path '*/\.*' -exec grep -Il '.' {} \; ...
user avatar
  • 547
12 votes

md5sum command binary and text mode

On GNU/Linux, the two modes always produce same result Yes, explicitly. From man md5sum: Note: There is no difference between binary and text mode option on [sic] GNU system. This is from the ...
user avatar
  • 82.7k
12 votes

Format output to a specific line length

Use fold as follows: fold -s -w80 file This will only split at whitespace (-s), using a line width of 80 characters (-w80). So it does exactly the same as the fmt solutions, but it also allows to ...
user avatar
  • 728
12 votes
Accepted

display filename followed by content without interaction

If the output from more is acceptable as it is, just pipe it through cat: more * | cat That will do away with the "more" prompts. Or you can get a bit more control over the display using printf in ...
user avatar
  • 75.4k
11 votes
Accepted

Format output to a specific line length

Use fmt instead: fmt --width=80 file From man fmt: -w, --width=WIDTH maximum line width (default of 75 columns)
user avatar
  • 144k
11 votes
Accepted

Debian - How to change Terminal background colors

In your Terminal, klick Edit > Profile Preferences > Colors See the Text and Background Color Uncheck the Use colors from system theme And set the Build-in schemes: to: Gray on black
user avatar
  • 1,371
10 votes

Is there something like a lorem ipsum generator?

found this at Bash One-Liners  tr -dc a-z1-4 </dev/urandom | tr 1-2 ' \n' | awk 'length==0 || length>50' | tr 3-4 ' ' | sed 's/^ *//' | cat -s | sed 's/ / /g' |fmt must be limited by another ...
user avatar
  • 217
10 votes

add filename as text in the corner of an image file

mogrify does batch processing so you could use something like this (change the font, size, color, position etc as per your taste): mogrify -font Liberation-Sans -fill white -undercolor '#00000080' \ -...
user avatar
  • 73.4k
10 votes

Earliest viewer for viewing .json files?

jq is a json processor (like sed for json) which can also be used to pretty-print json documents. cat yourfile.json | jq
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible