Questions tagged [tr]

tr is a *nix utility for character-level alterations to a stream. tr/// is a Perl operator named after this utility. For the tag used to build HTML tables, please use [html-table]. Use this tag only if your question relates to programming using tr. Questions relating to using or troubleshooting tr command-line options itself are off-topic.

tr (for "translate") is a standard utility in Unix, GNU/Linux, and other systems. It reads from standard input and writes to standard output, making specified character-level alterations.

One alteration it can make is to substitute individual characters, or groups of characters, with specified replacements; for example, tr a-z A-Z "translates" every occurrence of a lowercase ASCII letter to its uppercase counterpart.

Another alteration is to remove characters; for example, tr -d % "deletes" every instance of a percent sign, while tr -s % "squeezes" sequences of repeated percent signs (so that %% or %%% or %%%% or whatnot will become simply %). tr can also complement characters; for example, tr -cd '[:alnum:]' removes all non-alphanumeric characters.

tr/// is a Perl operator named for this utility. (It can also be written y///, after the same operator in sed.) It substitutes individual characters; for example, tr/a-z/A-Z/ translates every occurrence of a lowercase ASCII letter to its uppercase counterpart.

Beginners often try to use tr for replacements which are not character-level alterations. If you don't want to replace every instance of an individual character with something else, this is the wrong tool; perhaps look at sed, or the s/regex/string/ facility in Perl for regular expression (text pattern) replacement.

Links

675 questions
-1
votes
3 answers

With Sed, awk or tr, how to add a newline after a specific character?

I have this file: lol.txt:hungrylol2.txt:hungry lol3.txt:hungry lol4.txt:hungry lol5.txt:hungrylol6.txt:hungry And I would like to turn in into this…
aurelSon
  • 79
  • 3
  • 12
-1
votes
2 answers

caracter 'a' getting removed when I try to replace new line, tabs and consecutive spaces with a space

Below is the command I'm typing cat program.c | tr '\n' ' ' | tr '\t' ' ' | tr -s [:space:] ' ' >unreadable.c The output is Hi w ssup. How re you doing bro Its nice to see you g in bro . But the problem is character 'a' is getting removed from the…
sandywho
  • 353
  • 1
  • 7
  • 16
-1
votes
1 answer

C - mkfifo , ls - don't stop

#include #include #include #include #include #include #include int main(void) { if(mkfifo("fifo", S_IRWXU) < 0 && errno != EEXIST) { perror("Fifo…
Gwiazdek
  • 149
  • 1
  • 8
-1
votes
1 answer

bash leaning on TR to format anwsers

I have a really bad habit of abusing tr. I need to find another way, a different style. all I want to so is print the list horizontally instead of vertically - so I can cut and past it into an email. Check out the use of the TR command. Just…
capser
  • 2,442
  • 5
  • 42
  • 74
-1
votes
1 answer

I want ajax response inner html in working table tr

I have select option field and free input field in the table row (tr). when i choose some option the field feels with ajax. when i add new row i want feel input field that new row and not in the first row. it is table html code:
-1
votes
2 answers

Hex find 20 and replace with 00 in LInux

I have a very large file (21G) and I want to do a find/replace hex (find 20 and replace with 00). I was using tr < filename* -d '\000' > newfilename Obviously, this is only removing NULL. Any help would be amazing.
Mochael_DLite
  • 167
  • 2
  • 5
  • 14
-1
votes
1 answer

How can i use three blanks as a delimiter?

I need to set the delimiter from a : to three blanks. So far my code is as follows: cut -d f1,6,7 test | tr : ' ' Dont mind anything before the pipe, that is just for formatting of the file "test". It will replace the delimiter with one blank,…
Mitch
  • 21
  • 1
  • 1
  • 7
-1
votes
3 answers

Delete characters from a big file using vim or grep or other

I have one big file which are contains around 500000 numbers, some of those numbers contains URl,Passwords , as you can see in my below example for my file , i would like to delete those numbers and keep only those numbers that contain Url,Password …
jassim mishal
  • 73
  • 2
  • 12
-1
votes
1 answer

Locating and translating escape sequences to other values

What would you use to check for escape sequenced values? I have two inputs arg1 and arg2. If you enter ab\t xyz into the arguments. And then if you were to type in "ab\t" into the input you would get "xyz" as output. I hope this makes sense and im…
TheUnknown
  • 53
  • 2
  • 10
-1
votes
1 answer

Search & Replace Character In String

I am trying to write a basic Perl script to do some string manipulation. I get the "Existing_Value_To_Be_Changed" and the "New_Value" as user inputs. The file has multiple block of lines such as the following - foo_bar_xyz000123 := abcd (100010 …
-1
votes
5 answers

insert a character between instance of two characters

I have a csv file with X amount of lines in the following format P26439,341,P,L,,P26439,,-0.41 where everytime there is a double comma i.e. ,, I want to insert the word NA in between them so it would appear as ,NA, would anyone have a sed, tr, perl…
brucezepplin
  • 9,202
  • 26
  • 76
  • 129
-1
votes
3 answers

Make or use delimiter to separate results

I have SQL output with multiple results: 1 OI 021 141012 1321 0001242 4S 2 0080004 5 001 00014 6 000001 000000000000016973 6 0529540437 0000000000 2963526113 test 7 8 000000001 9 1 OI 021 141012 1321 0001242 4S 2 0080004 5 001 00014 6 000001…
Kalin Borisov
  • 1,091
  • 1
  • 12
  • 23
-1
votes
2 answers

Need "this" to reference tr and not [window object]

I have a table that has its rows generated by variables in my software and I want the rows to highlight when they are clicked. Here is my code: $("#varTable > tbody:last").append("
-1
votes
6 answers

Linux/Unix tr command, strange behaviour

I'm trying to use the "tr" command, and to use it's -d delete option. My purpose is to rearrange a list of files in order of date accessed. I have a file orderedFile with the following contents: Access: 2014-02-09 21:35:36.642598731 -0700 0)…
s.t
  • 13
  • 1
  • 7
-1
votes
2 answers

Remove tr elements class

How can I remove a class that is defined to a table row element using EXT JS or plain Javascript. The class I want to remove is x-grid-row-selected Using tr.removeCls('x-grid-row-selected) gives me an error: Uncaught TypeError: Object…
Jacob
  • 3,580
  • 22
  • 82
  • 146