LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 03:44 AM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

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

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:14 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
Open Source Consulting | Domain Registration