Linux Crash Course - The tr Command

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 47

  • @Not-THAT-ChrisPratt
    @Not-THAT-ChrisPratt ปีที่แล้ว +10

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

  • @alain-pierrep.312
    @alain-pierrep.312 ปีที่แล้ว +1

    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.

  • @CjqNslXUcM
    @CjqNslXUcM ปีที่แล้ว +9

    haha the wow with the period sounds so sarcastic.

    • @jimmyrichards5595
      @jimmyrichards5595 ปีที่แล้ว

      Just so. Even though when reading it in my head, it doesn't make a sound! 🙂

  • @jonathanrider4417
    @jonathanrider4417 ปีที่แล้ว

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

  • @maneeshpatel1594
    @maneeshpatel1594 ปีที่แล้ว +3

    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 è.)

  • @zionpsyfer
    @zionpsyfer ปีที่แล้ว +2

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

  • @SwiatLinuksa
    @SwiatLinuksa ปีที่แล้ว

    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.

  • @Mantecoso87
    @Mantecoso87 ปีที่แล้ว

    Congratulations, glad to see the channel growing!

  • @ruixue6955
    @ruixue6955 ปีที่แล้ว

    2:07 start
    6:22 for delete

  • @sodakk17
    @sodakk17 ปีที่แล้ว

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

  • @pctlc
    @pctlc ปีที่แล้ว

    Wow Congratulations on 300k awesome!!

  • @ChrisPinCornwall
    @ChrisPinCornwall ปีที่แล้ว

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

  • @dreamcat4
    @dreamcat4 ปีที่แล้ว +1

    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

  • @TheLakeJake3
    @TheLakeJake3 ปีที่แล้ว

    Studio always looking nicer jay!

  • @RoughGanome
    @RoughGanome ปีที่แล้ว +2

    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 , " " '

  • @samoylov1973
    @samoylov1973 ปีที่แล้ว +1

    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

  • @chancepaayokigarchha3663
    @chancepaayokigarchha3663 ปีที่แล้ว

    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.

  • @sussusamogus7831
    @sussusamogus7831 ปีที่แล้ว

    Thanks for the guide Jay :)

  • @lstyle3210
    @lstyle3210 ปีที่แล้ว

    Great presentation!

  • @heckyes
    @heckyes ปีที่แล้ว

    Oh damn, the new remixed version of the intro music is gg.
    Wow, new HD camera and studio lighting as well?

  • @krishnachaithanyaks9693
    @krishnachaithanyaks9693 ปีที่แล้ว

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

  • @samplesandtests
    @samplesandtests ปีที่แล้ว +1

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

    • @maneeshpatel1594
      @maneeshpatel1594 ปีที่แล้ว +1

      That is one of the things I use it for. As a toy example: echo "Today: " | tr '
      ' ' ' ; date

  • @peterjansen4826
    @peterjansen4826 ปีที่แล้ว

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

  • @kamurashev
    @kamurashev ปีที่แล้ว

    Nice 👍

  • @ubeaut
    @ubeaut ปีที่แล้ว

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

  • @dmac5678
    @dmac5678 12 วันที่ผ่านมา

    What’s the main difference with sed and tr

  • @mathieuleclerc4136
    @mathieuleclerc4136 ปีที่แล้ว

    is it possible to create a new text file where the tr changes have been made?

    • @davidmutua6971
      @davidmutua6971 ปีที่แล้ว

      Yes by piping it into tee command

  • @xtsdagger6956
    @xtsdagger6956 ปีที่แล้ว

    Not sure about the title, isn't crashing considered bad in an OS?

  • @Eric3Frog
    @Eric3Frog ปีที่แล้ว

    It’s basically a “find and replace” command.

  • @javabeanz8549
    @javabeanz8549 ปีที่แล้ว

    So they finally are changing advertising away from Linode.

    • @asv5769
      @asv5769 ปีที่แล้ว +1

      Not really :) Akamai acquired Linode.

    • @javabeanz8549
      @javabeanz8549 ปีที่แล้ว

      @@asv5769 They did that some time ago, but in March it was still advertised as Linode

  • @QuimChaos
    @QuimChaos ปีที่แล้ว

    sadly if you are using zsh this will not work 8/

    • @OhItsAnthony
      @OhItsAnthony ปีที่แล้ว +1

      You need to replace the square brackets with single quotation marks eg
      echo "Hello World" | tr [a-z] [A-Z]
      becomes
      echo "Hello World" | tr 'a-z' 'A-Z'
      If you want to use the :lower: and/or :upper: syntax then you'll need to just add single quotes around the square brackets, eg '[:lower:]'
      EDIT: edited for clarity

    • @QuimChaos
      @QuimChaos ปีที่แล้ว

      @@OhItsAnthony thanks!!!
      I was trying everything without square brackets and it worked for the ranges a-z && A-Z but not :lower: and similar...
      this works
      echo "Hello World" | tr a-z A-Z
      echo "Hello World" | tr '[a-z]' '[A-Z]'
      echo "hello World" | tr '[:lower:]' '[:upper:]'
      echo "hello World" | tr "[:lower:]" "[:upper:]"
      i guess just using quotes around the square brackets works

  • @rockymarquiss8327
    @rockymarquiss8327 ปีที่แล้ว +2

    Good thing you didn't have matthew@localhostt with the -s example... LOL

    • @javabeanz8549
      @javabeanz8549 ปีที่แล้ว

      I was expecting to see "hostt" "host"

  • @Laflamablanca969
    @Laflamablanca969 ปีที่แล้ว

    Rip linode. Time to move to digital ocean

    • @javabeanz8549
      @javabeanz8549 ปีที่แล้ว

      DO has it's own issues. 1) don't try sending outbound email from DO, it's blocked by big providers, like GMail 2) their support is not what I would call good, the last few issues I have had, they don't seem to bother actually reading the request, they cherry pick a few words and toss back a reply. 3) their prices went up recently, but I think Linode, now Akamai, did that as well.

    • @SlideRSB
      @SlideRSB ปีที่แล้ว +1

      Very surprising that Akamai decided to kill the Linode brand.

    • @javabeanz8549
      @javabeanz8549 ปีที่แล้ว +2

      @@SlideRSB I think that they should have marketed it as "Linode by Akamai"

    • @SlideRSB
      @SlideRSB ปีที่แล้ว

      @@javabeanz8549 That's what I thought they were going to do.

    • @Laflamablanca969
      @Laflamablanca969 ปีที่แล้ว

      It just shows that the brand Akamai is more important than the customer base of linode. Yeh, I’m out.