LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
examples for tr -t truncate


hi,

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 04:45 AM.
 
Old 04-19-2016, 10:56 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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 11:06 AM.
 
  


Reply


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 10:24 PM
how to truncate munna_dude Programming 5 07-26-2007 12:56 AM
how can i truncate this munna_dude Linux - Networking 1 06-16-2007 12:42 AM
how can i truncate this munna_dude Programming 24 04-12-2007 04:44 AM
how to use truncate sureshbabu Linux - Newbie 1 10-29-2003 05:22 AM


All times are GMT -5. The time now is 12:55 AM.

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