Linux Crash Course - The tr Command

preview_player
Показать описание
In the Linux Crash Course series, you'll learn the basics of all the must-know commands, one video at a time. In this episode, you'll be introduced to the tr command, which enables you to make adjustments to characters within strings of text.

LEARN LINUX TV - YOUR HOME FOR LINUX-RELATED FUN AND LEARNING!

*🐧 SUPPORT LINUX LEARNING!*
_Note: Royalties and/or commission is earned from each of the above links_

*⏰ TIME CODES*
00:00 - Intro
00:54 - Set up your very own cloud server with Akamai Connected Cloud
02:08 - The tr command is often used with other commands
02:34 - An example of the tr command in action
04:12 - Redirecting stdout into the tr command
05:39 - Using a file as stdin for the tr command
06:24 - Using the tr command to delete characters
07:43 - Using tr's "Squeeze" feature to remove duplicate characters
09:25 - Another method for changing case in a string using the tr command
10:23 - Deleting all alpha characters from a string using the tr command
10:50 - Replacing characters with the tr command

*Full Courses from Learn Linux TV*

*🌐 LEARN LINUX TV ON THE WEB*

*Content Ethics*

*⚠️ DISCLAIMER*
LearnLinuxTV produces technical content that will hopefully be helpful to you and teach you something new. However, this content is provided without any warranty (expressed or implied). LearnLinuxTV is not responsible for any damages that may arise from any use of the content and information that's being provided. The viewer is expected to follow best judgement and to make his/her/their best decisions while working with production or non-production software, systems and hardware.

#Linux #linuxtutorial #linux_tutorial
Рекомендации по теме
Комментарии
Автор

Congrats on 300, 000!
Another great video as always. Thank you so very much!

Not-THAT-ChrisPratt
Автор

Great video ! Here are my 2 cents worth of comments. Firstly, to the question "How tr differs from sed ?", I usually answer that tr works one character at a time and is (but it should be experimentally confirmed) probably more efficient than sed on certain simple transformations. Secondly, I always enclose tr arguments in single quotes to avoid shell expansion. Generally speaking, it's a good habit to "protect" with single quotes or backslashes what should be left untouched by the current shell. Let's assume that, in the current directory, we have only one file, named "b". The "tr [a-z] [A-Z]" command will be transformed in "tr b [A-Z]" by the shell before tr is executed. The result won't be what was expected.

alain-pierrep.
Автор

haha the wow with the period sounds so sarcastic.

CjqNslXUcM
Автор

One nice use of "tr" is to delete all characters (with the -d flag) that lie outside a certain range (with the -c flag). Thus, the command

tr -cd '\11\12\15\40-\176' < bad_file.txt > good_file.txt

will remove all non-ASCII characters from a bad file and save the result to a good file. (One should be aware, though, that this command will also get rid of characters like è.)

maneeshpatel
Автор

20+ years... how did I not know this? You sir, are always an awesome source of info. Thank you and congrats on 300k!

zionpsyfer
Автор

Thanks Jay got everything you doing. Your videos was inspiration for me to start using Linux 4 years ago, and 6 months later i started Linux channel in Poland. Thank you very much again.
Edit:
Congratulations 300k subs. Btw.

SwiatLinuksa
Автор

Well! I never knew that! I've been using Unix/Linux since the mid eighties, and I've never come across it. Thank you.

ChrisPinCornwall
Автор

Congrats on 300, 000! Keep up your fantastic work!

jonathanrider
Автор

congrats for the achievment. Hope to see your channel growing even more.

sodakk
Автор

Congratulations, glad to see the channel growing!

Mantecoso
Автор

fabulous community educational work you are doing here. to try to make interesting these historical unix commands. and very worthwhile. it brings back some memories of how i learned text manipulation in posix shell myself.... thing is that sny 1 single command is helpful to identify. but to make practical powerful usage requires stringing together with maybe n of m 'common vocabulary command set'.... the way i learned myself was to use sed as the main focus and starting point. and then to 'bring back' or reintroduce other commands (indeed like tr or cut). to make as a complement. my feeling is that this approach works because i use sed 's///g' so much frequently, almost in everything i can. that it's occurence in practical 'do some text manipulation operations on a random thing' works so often. of course in combination with other ubiquitous posix compliant syntax, cmds and builtings. for example the $() command substitution. and whatever else....

still it is a 'tough road' for the newcomer, and the real learner for me was with a process of trial and error, testing isolated statements until they executed correctly and gave the valid and intended desired output.... to then have a demonstrated confidence to move on to chaining multiple such commands together. as inputs and outputs to the next shell fraqment etc. whether it be a variable assignment, or a pipe, or a conditional evaluation.

i hope my input is well received. because people probably feel dumb to make so many simple errors for so long. but if you can demonstrate a real life workflow.... warts and all. including some genuine mistakes. then i think that would be great! along also with side discussions about 'general areas of proficiency'.... which for example one of those would be to master string quoting and string escaping. then also with some sort of 'timelines' or general expectations of how many weeks months or years it takes to really become proficient and second nature. i myself took several years. with a handful of larger projects. plus many smaller individual personal scripts.

perhaps an example of a simple script, that an individual user might find they need? well one script i wrote was to control volume on my pc, for specific hardware device, to wire up to global hotkeys. to set levels on alsa instead of pulse audio. another example was to auto upgrade apt sources. and probe / test them after ubuntu os upgrades. and many other such personal scripts, that we do to simply make our lives easier and more comfortable. to fill in the gaps where there is no out of the box solution. but we want the computer work in specific ways and have a good feeling that the specific goal is an achievable outcome. and many other scripts, a simply countdown timer that uses 'termdown', but then after that launches 'xcowsay' + plays an audible alert sound that repeats several times. whereby the input arg1 to the 'timer' script is a text sting in the format '40s' or '3h24m'... things like this. and believe it or not.... there was no pre-existing solution to that one! i really did have to write my own custom script for it. i am sure you also can think of many of your own general purpose or 'special purpose' examples too.

but what is more important is to give users the feeling they can pro activelt, and creatively invent their own scripts, whenever they are unhappy or spot a glaring effeciency gap in their everyday workflows...although i suppose a lot of users resort to python these days. instead of writing traditional posix compliant scripts, and sticking to that as the iso standards modernized version of the original k&r bourne shell. ah well! ....to let them deal for the python bugs instead. and maybe some slower process launch times. different sets of pros/cons all of it

dreamcat
Автор

Useful command. I use this command to translate commas into spaces in a file. Then I can use awk to parse the separate fields. The problem is, there are spaces before and after the commas sometimes and other times no spaces at all. Using TR, fixes all of the comma issues 'tr, " " '

RoughGanome
Автор

Congratulations on 309 000 subscribers! For those in zsh these 'tr' commands will be:
% your_phrase="Your phrase"
% echo ${your_phrase:l}
% echo ${your_phrase:u}
respectively

samoylov
Автор

Jay my brother, can you make a series on AWK and SED ?
Besides, I think your channel lacks the content regarding Disk Management..Can you prepare a solid series on Disk Management? It would be a hit for sure.

chancepaayokigarchha
Автор

what if you want to remove a non ASCII character like: Null, Line feed, EOF, etc?

samplesandtests
Автор

Oh damn, the new remixed version of the intro music is gg.

Wow, new HD camera and studio lighting as well?

heckyes
Автор

What’s the main difference with sed and tr

dmac
Автор

I use that command to get the RAM-usage and battery-usage in my 'panel' (xsetroot).

peterjansen
Автор

Hi Mr. Jay,
Can you please make a Crash Course on LDAP authentication and Authorisation in Linux?

krishnachaithanyaks
Автор

Does tr command work with other languages? How would [a-z] work? I guess [:lower:]?

ubeaut