Using tr and dos2unix

THE TRANSLATOR

Article from Issue 53/2005
Author(s):

The tr tool is a real wizard. This simple command lets you replace strings in text files. Whether you are replacing letters or just removing whitespace, you will be amazed at tr‘s versatility.

The tr command replaces characters

in text files. The command

reads the standard input and

sends the results to standard output. But

of course, you can use the familiar operators

to redirect both streams. In fact, tr

really shines in combination with other

shell commands.

Simple Replacements

The tr command expects two strings as

arguments and replaces all the occurrences

of the first argument in a text

with the second argument. This may

sound complicated, but let’s look at a

simple example. The following command

replaces the “e“s in “Petronella”

with “a“s:

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: sed

    Working with a text editor can be difficult if you need to handle frequently recurring tasks or multiple files. sed can save a lot of typing.

  • Dwdiff Shows Changes Word for Word

    Version 1.3 of dwdiff, a free front-end for the Unix diff program has just been released and is now licensed under the GPLv3.

  • Most Is More Than Less

    If you like to customize your command-line file pager, check out most.

  • PHP-CLI

    PHP is not just for websites. Command-line PHP scripting has been around for more than 10 years, which makes the language and its comprehensive libraries eminently suitable for the toolbox of any administrator who manages web servers.

  • Bulk Renaming

    When it comes to renaming multiple files, the command line offers time-saving options in the form of mv, rename, and mmv.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News