7 Linux Text-Processing Tips to Get the Most Out of Your Plain Text


While Linux isn’t strictly a text-only system, it has a reputation for making better use of plain text than any other operating system. While many tools cater to programmers, writers, and authors can also take advantage of these powerful tools. (They’ll also work in the macOS and Windows Subsystem for Linux terminals.)

7

Compose in an Editor

Article text in Vim.

Being a writer, I know how word processors are such valuable tools for writing. The vast majority of real work I’ve done with a computer has been “document preparation.” As a Linux user, it’s also difficult to avoid using a plain text editor for my configuration and coding projects.

Related


Why You Need a Plain Text Editor

Sometimes, keeping it simple is the best option.

While text editors like Vim are mainly intended for code, they can also be useful for prose. They’re different than word processors because they only let you edit plain text without formatting. But this is the key to their power for writing. Many writers yearn for “distraction-free writing environments,” even shelling out money for them, but the kinds of text editors available for Linux offer the same thing for free. And you don’t even have to be a Linux user or know anything about the terminal to take advantage of them. Many of them are already available for Windows or Mac. With a text editor, it’s just you and the words. This can be useful for anyone who writes anything from essays to novels.

6

Use External Spell-Checking

ispell running in the Linux terminal.

Anyone who’s ever written anything in a word processor has seen the dreaded red squiggle below their words. Even if you try to keep writing, it’s there, highlighting your mistakes. The spell-checker seems to be mocking you. Even worse, it’s a distraction. But you still need it. Even the best writers make typos. Our fingers get ahead of our brains sometimes. Or maybe the morning coffee has yet to kick in. But there’s an answer for writers.

The traditional way of designing programs in Linux, inherited from Unix, is to make them modular. The ideal is a program that does one thing and does it well. This is a hallmark of the “Unix philosophy.” It’s meant to be a guiding light for developers, but the idea can easily be applied to writing words as well as programs. After you’ve picked an editor, you can compose in a distraction-free environment and run your spell checker when you’re ready to proofread your work.

A good example of one such tool is ispell. You run it on a text file, and it will run through it and offer spelling suggestions for words it flags as possible mistakes. It’s similar to the built-in spell checker, but in a separate program. You get the best of both worlds: a way to focus on your writing and another pair of eyeballs to spot mistakes.

5

Layout In Another Program

Markdown basic syntax homepage.

The advantage of using a plain text editor for your writing is that you can focus on your piece instead of formatting. With plain text, you don’t need to figure out italics or boldface. Your editor can’t do that if you wanted to. “Plain text” means plain text. It’s encoded in ASCII or increasingly in Unicode.

For your finished product, you will want to define how your document looks. If you’re writing a blog post, you can just paste it into the post editor page and then format your headings and links. A lot of programs now use Markdown, which lets you set italics or boldface for emphasis rather than raw HTML. You can learn more about Markdown on the Markdown Guide.

If you have even more advanced needs, like typesetting lots of math, Linux has you covered. One thing that convinced Bell Labs to deploy an OS that some of its researchers had created, according to Unix co-creator Dennis Ritchie, was a typesetting system called “troff.” Adopting this was an attempt to manage the large amount of paperwork the company’s patent department generated. With all of Bell Labs’ inventions in the 20th century, including Unix, they were pretty busy. It survives in open-source form as groff, and is now mainly used to create Linux manual pages.

The other major technical typesetting system is LaTeX, an offshoot of the TeX typesetting language created by legendary computer scientist Donald Knuth. This system is widely used in academia and technical publishing, like textbooks and scientific journals. It’s popular because of its ability to easily typeset mathematical symbols. It’s a cross-platform system, and though it’s not strictly a Linux program, given that Linux is popular among scientists and engineers, LaTeX is pretty common. Several implementations exist for Linux. It’s even become popular among people self-publishing books that don’t have any math in them because the output looks so good. LaTeX-typeset documents have a style that you’ll instantly recognize when you see it.

The idea behind all of these systems is that you compose your text and mark it up when you want to format it. If you’ve ever coded a web page from scratch, it’s a similar idea.

4

Use wc

If you write in a journalistic fashion or for freelance clients, you’ll often have to hit a word count. You might miss the word count function in your word processor. Fortunately, Linux comes with a word count program. It’s called wc.

You can call wc from the command line. It works on standard input or from files.

You can run it on a file with this command:

        
wc file.txt

You’ll get a count of the number of characters, words, and bytes. You’re most likely just interested in the words. The -w option will give you just the number of words:

        
wc -w file.txt
wc-w run on the article title.

The only problem is that if you’re like me, you might keep watching your word count. Working on your text in a separate editor can help you keep on task.

3

Integrate Text Processing Tools to Use Linux as a Word Processor

The trend in software development is to use Integrated Development Environments (IDEs) that include an editor, a debugger, file and library browsers, version control, and possibly a command-line terminal. A modern word processor is similar: you have an editor, a spell checker, formatting buttons, and file opening and saving tools.

It’s possible to use the Linux terminal as an IDE simply by running tools in multiple windows. You can do the same with text processing tools. You might compose your document in one window while running the spell checker in another. You might manage your files in another terminal window. A lot of tools that were invented to manage code will work for plain text as well.

2

Use Regular Expressions for Precise Searches

Regular expressions, or regexes, are a useful tool for managing text. You can specify patterns right down to the character.

The most common Linux regular expression command is grep. You can search for basic patterns:

        
grep 'foo' example.txt

You can also search for a specific pattern:

        
grep 'f.*o' example.txt
grep output of a search, with matches highlighted in red.

This will match an “f,” followed by any other character, followed by an “o.” It will match words like “food.” The matches are highlighted in red on this implementation.

This is scratching the surface of what you can do with regular expressions. There is much more than I can explain in a short section.

Related


8 Tasks You Can Automate Using Regex

Regex or regular expressions are a great way to automate things.

1

Use Search And Replace

You might be familiar with search and replace commands on your word processor to save time making repeated changes to your document. You’ll be pleased to know that many Linux editors have this feature.

A good example is Vim, though the syntax might be a little weird. Here’s a global search and replace on an entire document:

        
/s/foo/bar/g
Vim global search and replace command in the terminal.

This tells Vim to change every instance of “foo” to “bar” across the entire file. Omitting the “g” at the end will just change it on the line the cursor is on.


This is just the start of your journey into text processing on the Linux command line. With practice, you can set up a distraction-free writing environment while employing powerful commands.



Source link

Previous articleBungie’s Marathon is doomed — ARC Raiders is so much better