• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / LPIC-1 Exam 101 / LPIC-1 Translating with tr

LPIC-1 Translating with tr

May 10, 2015 by The Urban Penguin

For this LPIC-1 objective, 103.2 we look at using the Linux command tr to translate and delete characters. This objective has look at many of the smaller tools that you can use within Linux but these all build to make a strong tool-set. No matter if the tools are used by themselves are part of a command pipeline

Examples with tr


The Linux command tr allows you to translate single characters,additionally we can delete characters and squeeze them. Squeezing is not quite as fun as it sounds but is very useful in removing additional spaces

We will start with the first example of tr and will use it to convert lowercase strings to uppercase:

echo "a b c" | tr [a-z]  [A-Z]
A B C

Now although this may well work for you and it will work, Linux likes to be able to provide alternatives; this could also be written as:

echo "a b c" | tr [:lower:]  [:upper:]

Don’t you just love choice, you can now choose your favorite and stick with it but you will need to understand both methods for the LPIC-1 exam and also for reading other people’s scripts

In the nest example we look at using tr to delete newline characters , the n, the command line  we could use would be similar to this:

echo -e "a nb" | tr -d "n"
a b

We can see from the output that the a an b are on the same line and we have removed the newline from the echo string.

For example three, when you are ready, we will squeeze or suppress contiguous spaces we could use code similar to the following

echo "a b     c" | tr -s [:space:] 
a b c

Suppressing the extra spaces ensures just single spacing between words or fields; this may be useful when displaying the /etc/fstab file that always has additional spaces:

cat /etc/fstab |  tr -s [:space:]

Hopefully you too can find some great ways to use this and you start practicing with tr as soon as you can. Take a look at the video and before to establish a great foundation for your LPIC-1 certification.

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: LPIC-1 Exam 101

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Linux Technologies
    • Apache HTTPD Server
    • Learning PHP
    • Learning PUPPET
    • Learning SAMBA
    • Linux File-Systems
    • Monitoring with Nagios Core
    • MYSQL
    • openLDAP Directories on Linux
  • LPI Training from The Urban Penguin
    • Complete Linux Essentials
    • Live and Pluralsight hosted courses
    • LPI Linux Essentials
    • LPI Linux Essentials for Raspberry Pi
    • LPIC-1 Linux Administrator
    • LPIC-2 Certified Linux Engineer
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
  • Online Instructor-led Courses
    • Bash Scripting Masterclass
    • Nftables Masterclass
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
  • OpenStack
    • Citrix Videos
    • Pluralsight
    • Raspberry Pi Tutorials
    • Udemy
  • Operating System Tutorials
    • Learning SUSE
    • Learning Ubuntu
    • Linux Foundation Training
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
    • Solaris 11 OCA 1ZO-821
  • Scripting – the power of repetition!
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
    • Learn C Programming using Linux and the Raspberry Pi
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell

© 2022 The Urban Penguin · All Rights Reserved