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.

  • Command Line: Ispell and Aspell

    Nobody is safe from typos and jumbled up words. Spellcheckers like Ispell and Aspell keep the letters in the right places.

  • 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.

  • Command Line: dd and mkisofs

    Whether you are creating backups, rescuing data, or burning bootable CDs, dd and mkisofs help you handle the job in style.

comments powered by Disqus

Direct Download

Read full article as PDF:

Commandline_tr_dos2unix.pdf (277.88 kB)

News

njobs Europe
What:
Where:
Country:
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia