2022 Developer Survey is open! Take survey.

Questions tagged [tr]

For questions pertaining to tr, a utility that translates or deletes characters. Use this tag for questions about the tr utility itself, or questions about issues arising from its use.

Filter by
Sorted by
Tagged with
3 votes
2 answers
355 views

tr command unable to process colour output piped from grep

I'm running macOS 12.3.1 I added a couple of lines to my .zshrc, viz. export GREP_OPTIONS='--color=always' export GREP_COLOR='1;35;40' After this, when I pipe grep output to tr, it returns the same ...
user avatar
  • 53
2 votes
2 answers
102 views

replacement for tr with utf-8 capabilities

in order to isolate the last word in any line of a poem (to have a list of all rhymes), I put together several snippets of code obtaining this awk '{print $NF}' input.txt | tr 'A-Z' 'a-z' | tr -sc 'a-...
user avatar
  • 297
2 votes
1 answer
137 views

replace character only when it's not inside curly braces (sed, awk, tr, ...)

I have a string called "desktops" that look like this: desktops="1 2 %{F#990000}3%{F-} 4 5 6 7 8 9 0" The 6 digits after the "#" represent an RGB color, so the 3rd ...
user avatar
0 votes
4 answers
47 views

concise but readable way to extract the numerical value after the substring "mode:" in a shell script

I have this string: DMT mode 4: 640x480 @ 60Hz 4:3, clock:25MHz progressive I want to extract from it the mode number (the part before the first :), which in this example is 4. As you might ...
user avatar
  • 191
0 votes
5 answers
492 views

Remove all characters till the first letter ([a-zA-Z]) in a string

I want to remove all characters till the first letter [a-zA-Z] in a string. For example: #121Abc --> Abc %Ab#c --> Ab#c Ab#c --> Ab#c Abc --> Abc 1Abc --> Abc 1 21Abc --> Abc 1^1 ...
user avatar
  • 1,364
0 votes
1 answer
60 views

Explanation of pipeline containing egrep, tr and expand

Can someone explain the following pipeline to me? I am trying to filter a list of ports in services so that only the unique port names are listed out. What exactly do expand and tr do, and what does ...
user avatar
  • 37
-1 votes
2 answers
49 views

Replace empty spaces with TAB except in last column

I have a file that looks like this. How can I replace each empty space with a TAB except in the last column that starts with ID? chr1 13513 14763 Medtr1g004950 . + JCVI gene . ID=Medtr1g004950;Note=...
user avatar
2 votes
4 answers
165 views

Unable to exclude lines containing ^M from grep

I have the following file from which I want to extract only Removed '2022-01-30_01-00-05', at the end. Removing '2022-01-30_01-00-05'... 0.46% complete (00:03:45 remaining)^M 5.49% complete (00:00:...
user avatar
  • 253
0 votes
2 answers
35 views

what does (tr \\n \\0 <file.txt) mean?

context: https://stackoverflow.com/a/13941223/15603477 I do understand xargs chmod 755 <file.txt For bigger amount of files, or almost any number of lines in your input file... For many binutils ...
user avatar
  • 411
3 votes
9 answers
669 views

Convert line with words enclosed by single quotes and separated by comma to a column

I have this file: 'dog', 'cat', 'horse', 'turtle' I want to convert the line to: dog cat horse turtle if I use just the comma as separator and command tr I can do: tr -s ',' '\n' < file with the ...
user avatar
7 votes
2 answers
253 views

Escape characters in sed transliterate

I want to use sed's transliterate (y///) to replace one set of characters by another. I would expect this to work just as well as using the tr program. $ echo '[]{}abc' | tr '[ab}' 'gefh' g]{hefc ...
user avatar
0 votes
1 answer
39 views

When is it beneficial to add -u to tr?

One of the arguments to the tr command is: -u Guarantee that any output is unbuffered. Under what circumstances is it a good idea to not buffer the output? e.g. should I use -u if I expect each ...
user avatar
4 votes
5 answers
883 views

How can I transliterate some characters 1-to-1, leave some unchanged, and replace others with the same target character?

I have a file called file.txt containing: MAL TIRRUEZF CR MAL RKZYIOL EX MAL OIY UAE RICF "MAL ACWALRM DYEUPLFWL CR ME DYEU MAIM UL IZL RKZZEKYFLF GH OHRMLZH" I'd like the characters ...
user avatar
0 votes
1 answer
1k views

what does the following tr command do?

I am looking at a .sh script and one of the lines is the following: tr -d '\15' < file1.txt > /testProject/files/file1.txt i understood the part file1.txt > /testProject/files/file1.txt ...
user avatar
0 votes
2 answers
81 views

Reassigning a variable using tr and getting rid of new line and carriage returns

I have a particular string loaded into a variable (v1). I want to define a new variable equal to this variable MINUS the new line and carriage returns so thus I need to delete the new line and ...
user avatar
3 votes
7 answers
698 views

How to remove \n in a string

I have a tab delimited text file where the 23rd column with string has \n in it which causes it to break to the next line. I opened the text file in vi and enabled white space characters and I can see ...
user avatar
  • 29
0 votes
2 answers
80 views

String Extraction

I have a file with the text pattern: AAAA - BBBB (CCCC) - (DDDD) I'm only interested in using the first set AAAA - BBBB individually (i.e. AAAA and BBBB) I've chopped off the '(CCCC) - (DDDD)' using: ...
user avatar
1 vote
3 answers
585 views

how to replace every non-ASCII UTF-8 character with zeros in file

The source is source is UTF-8 only... need to replace every UTF-8 character other than the ones that are part of the ASCII character set (code points U+0000 to U+007F) with zeros like below line, This ...
user avatar
3 votes
5 answers
1k views

Bash - remove dashes and new-lines before replacing new-lines with spaces

I have a bunch of text files in the following format: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam ...
user avatar
  • 4,760
2 votes
3 answers
564 views

how to find which special character are there in the file and replace those character with zeros

I have a file with below format.. this is file data under the file 123�45 this is second line 123¿ I want o/p like this. this is file data under the file 123045 this is second line 1230 The source ...
user avatar
0 votes
2 answers
69 views

Is there a way to strip the high bit of each byte in a file?

I've been trying to figure out if this can be done in sed or tr, but I can't find it. I have a bunch of files from an old Apple II which have the high bit set on each byte. On a Mac, this results in a ...
user avatar
  • 113
0 votes
1 answer
145 views

What exactly these tr commnads do?

I am rewriting some commands that were run using WSL on a Windows machine and need to accomplish the same thing in Python. I am having a really hard time figuring out what exactly these commands are ...
user avatar
0 votes
2 answers
40 views

Bad columns formatting by the tr command [duplicate]

I have a file like this AAA:111111:FIRSTLINE BBBBBBB:22222222222:SECONDLINE CCC:33333333333333333333:THIRD LINE And I wanted to change each ":" by a tab. For that, I used the tr command tr &...
user avatar
2 votes
1 answer
178 views

Rename file with contents of file

So I've downloaded a bunch of text files and want to rename these files to the title that is contained within in those files. The output of head sn-800.txt is: GIBSON RESEARCH CORPORATION ...
user avatar
  • 5,572
2 votes
3 answers
110 views

How can I use sed or tr to delete strings like "[digits]"?

I recently had to handle lots of downloaded paper, which included many annoying "[...]" in the text. Like this: Local delivery of a wide selection of growth factors [e.g. platelet-derived ...
user avatar
0 votes
1 answer
36 views

Delete characters from a certain point

I want to get all the files that are written in bash so I use this command IFBASH=$(grep -Fx #!/bin/bash *) It works. Output: test.sh:#!/bin/bash t test2.sh:#!/bin/bash All this is saved in the ...
user avatar
3 votes
1 answer
147 views

Using SED, TR or AWK to capitolise the first letter

I have a giant text file of potential passwords that I use for ethical pen-testing. I want to get a bit more variation of my passwords by getting the first letter of a given password to be capitalized....
user avatar
0 votes
1 answer
229 views

Convert Binary Data Stored as ASCII to Binary

I've got a load of binary data stored as ASCII text in a file like this: 0b 0000 0001 0b 0000 0000 0b 1111 0001 etc How would I convert this to a raw binary bitstream, and save it to disk? Can this ...
user avatar
-5 votes
3 answers
68 views

So I have a wordlist that I'm creating suited for a particular domain and I'm trying to get rid of the forward slashes [duplicate]

Basically I want to get rid of the forward slashes but I'm not as familiar with sed/awk as I should. Can someone help me out here. Edit: I'd also like to mention that the worlist is over 1000 lines ...
user avatar
4 votes
1 answer
487 views

How to use the tr REPEAT modifier to replace a character with a repeated character?

I'm using the tr command to replace newlines with tabs from an output of another command, and I want to have multiple tabs to better align the output to a columnar format. I see that tr has a [CHAR*...
user avatar
  • 143
0 votes
1 answer
206 views

Bash - make counter print superscript numbers

If I had a script with a counter, printing numbers like this: #!/bin/bash while true; do i=$((i+1)) echo "$i" done; prints: 1 2 3 4 5 [...] how can I make the script print superscript ...
user avatar
  • 4,760
0 votes
1 answer
43 views

replace any in txt file excipt range of letters

Please I have a txt file, I want to replace anything to _ except this range of letters [\0600-\06FF]. like sed 's/^[\0600-\06FF]/_/g' < a. txt > b. txt not work with me.
user avatar
  • 47
0 votes
7 answers
1k views

Combining all rows in single row with coloumn seprator in unix

I'm having the unix output as ABC : 123 DEFG : 4587 MJk : 36 I want to combine all the rows in single row with same separation like ABC DEFG MJK : 123 4587 36 I know to use awk to print output in ...
user avatar
  • 3
5 votes
4 answers
4k views

how to use tr to replace multiple sets?

I want to use tr to replace digits 0-5 with A and digits 6-9 with B. I tried using sed to do this: sed 's/[0-4]/</; s/[6-9]/>/' It works only once though so for example if I write 123 it will ...
user avatar
  • 59
1 vote
0 answers
71 views

Inconsistent behaviour when piping output of Tail into Xargs through an editing command

I'm giving in to asking the SE spirits for assistance. I will expand in detail below, but I've boiled the inconsistency down to these 3 lines. I am trying to grep a string in between single quotes (...
user avatar
  • 302
-1 votes
2 answers
1k views

tr and rot13 question

I'm playing Bandit by OverTheWire. On stage 11 they ask you to translate a data file with this plaintext "Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh". I know that the solution is to use this ...
user avatar
3 votes
1 answer
60 views

How to append .md to any word before the delimiter ' "wikilink"'

Thank you for taking the time to read this post. As mentioned in the title, I'm trying to append .md to any word before the delimiter "wikilink". The issue is the word changes depending on the file ...
user avatar
  • 31
2 votes
1 answer
114 views

character replacement with sed vs tr

The system in question is a Raspberry Pi running current Raspbian "buster". One can get the CPU Temperature using the following: $ vcgencmd measure_temp temp=53.0'C The ' may be replaced with ° ...
user avatar
  • 2,114
0 votes
2 answers
88 views

Can any one explain this code for Ceaser Cipher

IN="MJHVIZN ZPIO YJHPN" for I in $(seq 25); do echo $I $IN | tr $(printf %${I}s | tr ' ' '.')\A-Z A-ZA-Z done Can Any one explain this code. I am confused with this nested statement echo $I $...
user avatar
3 votes
0 answers
52 views

Is this a bug in 'tr'? [duplicate]

My terminal is set to UTF-8. If I type this: echo -n 'ýá' | xxd I can see this output: 00000000: c3bd c3a1 Which is fine. Now I would like to remove the 'ý' character from the string, so I use: ...
user avatar
1 vote
0 answers
204 views

Using tr to convert newline to null stops stream output

I'm using the saw and jq plus some filtering to get pretty-printed JSON log streams, but what I have below has no output. It just hangs. saw watch /aws/ecs/container-log \ | sed -e 's/^\[.*\] \(.*\)(....
user avatar
  • 119
0 votes
2 answers
42 views

Using tr to reformat a txt file so that each lines contains 1 word

I want to modify a file to remove all punctuation, numbers and uppercases and also change the file so that there is only 1 word per line exemple: Hello, how are you! hello how are you With ...
user avatar
0 votes
1 answer
24 views

Using tr to place the words of a file in order so that each line contains 1 word in order of appearence and without spaces

I want to remove the special characters of a text files for that I found the following command tr -d '[:punct:]' < file.txt But, I also want to change the format of the file so that each line ...
user avatar
0 votes
2 answers
270 views

Bash: ignore special character

I have this code cat SomeFile | tr -cs '[:alnum:]' '\n' |tr -d 0-9 | tr '[:upper:]' '[:lower:]' > net.txt I want to read a file and ignore those characters.The output would be one word per line ...
user avatar
0 votes
2 answers
599 views

parsing variable which contains vertical bar

I have a bash script that involves the output of yad. By default, yad outputs its results separated by pipe characters "|". I have a string variable output. Echoing it shows it contains this: /dev/...
user avatar
  • 141
8 votes
2 answers
2k views

Why doesn't the command tr "\'\\\"\?\!" "01234" work?

In terminal, if I define some variable char as follows: export char=\'\\\"\?\! In effect, char is the string '\"?! And then I use the tr command to replace '\"?! with numbers 01234 tr "\'\\\"\?\!"...
user avatar
  • 81
0 votes
2 answers
466 views

tr with line number

This is example of tr output user@linux:~$ tr $ '\n' <<< 'abc$def$ghi' abc def ghi user@linux:~$ Would it be possible to add line number to each line? E.g. user@linux:~$ tr $ '\n' <&...
user avatar
0 votes
1 answer
384 views

why does the output of `ls` look different when piped through ``tr "\n" "\n"`?

The man page for tr(1) says: tr - translate or delete characters SYNOPSIS tr [OPTION]... SET1 [SET2] DESCRIPTION Translate, squeeze, and/or delete characters from standard ...
user avatar
  • 155
-1 votes
4 answers
2k views

If any first-in-line English letter is lowercase, uppercase it

I have a markdown document myfile.md with a list of English sentences in which some the first letters are lowercased and some are uppercased. All English sentences start with standard English letters; ...
user avatar
4 votes
3 answers
3k views

How to change any text to Proper Case and Sentence case using tr?

According to https://caseconverter.com/ “Upper Case” WHICH CONVERTS ALL THE LETTER INTO CAPITALS LIKE THIS. “Lower Case” which converts all the letters into small letters like this. “...
user avatar