Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-19-2016, 03:44 AM   #1
arun natarajan
Registered: Jun 2014
Posts: 108

Rep: Reputation: Disabled
examples for tr -t truncate


am not able understand tr translate cmd with option -t truncate.
according to man pages -t, --truncate-set1 first truncate SET1 to length of SET2

my work around:

[root@server cg]# echo "hhi hello" | tr -t [hh] [h]
]]i ]ello
[root@server cg]#

even from my abv example, i dont understand what is doing.
if anyone ve better examples, plz let me know.

Last edited by arun natarajan; 04-19-2016 at 03:45 AM.
Old 04-19-2016, 09:56 AM   #2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,706

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
It forces a one-to-one mapping... and prevents translating characters that have no matching replacement.

In your test, the [hh], gets truncated to [hh... thus every h translated to ].

You need a better test. Try "echo abcde | tr -t abc fg"

Here the "set1" list (abc) gets trunctated to "ab", so every "a" gets translated to "f", every "b" gets translated to 'g". And the output is "fgcde". "c" doesn't get translated as the string abc was truncted to ab.

Without the -t, the "c" gets translated to the last character of set2 - a "g", thus the output is "fggde".

Last edited by jpollard; 04-19-2016 at 10:06 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
truncate help munna_dude Programming 8 10-18-2007 09:24 PM
how to truncate munna_dude Programming 5 07-25-2007 11:56 PM
how can i truncate this munna_dude Linux - Networking 1 06-15-2007 11:42 PM
how can i truncate this munna_dude Programming 24 04-12-2007 03:44 AM
how to use truncate sureshbabu Linux - Newbie 1 10-29-2003 04:22 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration