Skip to main content

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
-1 votes
1 answer
37 views

sed and tr not replacing mystery control character

root@calleva:~# echo "f" > file root@calleva:~# f=$(<file) root@calleva:~# echo "$f" f root@calleva:~# echo "$f" | tr -c '[:alpha:]' '_' f_root@calleva:~# echo &...
Richard Barraclough's user avatar
-1 votes
2 answers
231 views

How does the `tr` command work?

I was playing around with tr and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command ...
BadHorsie's user avatar
  • 141
2 votes
0 answers
82 views

The paste command is outputing tabs instead of new lines when used with process substitution

The first command below produces each number on a separate line, and I would expect the second command to do the same thing because the only difference between the two is that we are using echo '1 2 3'...
sudocracy's user avatar
  • 221
0 votes
1 answer
79 views

Need help with a script that mv (renames) filenames that require single quotes in ls output or file operations

I need help with a script that mv (renames) filenames that are shown with single quotes in ls output or files that require single quotes for file operations. The script will be used to rename all ...
Psilospiral's user avatar
5 votes
1 answer
331 views

Why does 'tr' with '-c' option and set 2 extension add an unwarranted character to the end?

I wanted to use tr to substitute "illegal" characters in a string with a replacement character, where "illegal" characters are all outside of a set of "allowed" ...
AdminBee's user avatar
  • 22.9k
0 votes
2 answers
129 views

How to combine tr with xargs and cut to squeeze repeats

The top answer to this question demonstrates that cut can be used with tr to cut based on repeated spaces with < file tr -s ' ' | cut -d ' ' -f 8 I want to get the remotes of several Git repos in ...
Anil's user avatar
  • 221
0 votes
1 answer
134 views

Transforming a filename with 'tr' using RegEx doesn't work

I want to use the tr command to rename something like filename.ext to someName.ext. To do that I've tried echo "filename.ext" | tr -c ".a-z" "someName"` to replace the ...
Abhishek A Udupa's user avatar
5 votes
3 answers
394 views

Processing a continuous single line of data with stream processing in bash pipeline?

I am debugging an embedded server that outputs a continuous single line of text to a specified network port. There is no newline anywhere in the stream but it is text data and I would like to format ...
stmfunk's user avatar
  • 193
0 votes
5 answers
512 views

How to merge lines in groups of three

I have a file containing the below pattern, up to 2000 lines. For every group of three lines, the pattern repeats with different numerical values, but text values at the beginning are common up to ...
C S Pallapu's user avatar
3 votes
1 answer
2k views

tr replace not with space but delete char

I have a string animal: dog and I would like to transform to have just animal dog (one space between). e.g: echo 'animal: dog' | tr ':' ' ' animal dog There's 2 spaces above. I tried making the ...
Doug Fir's user avatar
  • 143
0 votes
0 answers
36 views

Why tr redirected to dd unexpectedly cuts data stream? [duplicate]

I'm able to fill 1MB file with specific character like this: > tr '\0' '#' </dev/zero | dd of=1MB.bin bs=1k count=1024 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied,...
ardabro's user avatar
  • 159
0 votes
1 answer
202 views

tr not working inside function

I am new to trying to write bash functions, so maybe I'm doing something wrong, but when I execute: myfile=test.txt cat $myfile 2>&1 | tee "cat_$(echo "$myfile" | tr . _)_$(date +...
Joe's user avatar
  • 103
3 votes
2 answers
696 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 ...
Shriram's user avatar
  • 216
2 votes
2 answers
720 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-...
Dingo's user avatar
  • 329
2 votes
1 answer
216 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 ...
ElTitoFranki's user avatar
0 votes
4 answers
123 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 ...
Al Ro's user avatar
  • 223
0 votes
5 answers
4k 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 ...
Porcupine's user avatar
  • 2,056
0 votes
1 answer
392 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 ...
pinky's user avatar
  • 37
-1 votes
2 answers
225 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=...
Igor Lalin's user avatar
2 votes
4 answers
471 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:...
NoExpert's user avatar
  • 489
0 votes
2 answers
2k 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 ...
jian's user avatar
  • 577
3 votes
9 answers
2k 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 ...
Emilio Galarraga's user avatar
7 votes
2 answers
844 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 ...
Jason Hemann's user avatar
0 votes
1 answer
125 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 ...
falsePockets's user avatar
5 votes
5 answers
1k 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
2k 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 ...
Amreen Fatema's user avatar
0 votes
2 answers
2k 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 ...
Prospero's user avatar
3 votes
7 answers
3k 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 ...
ntropi's user avatar
  • 37
0 votes
2 answers
93 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: ...
Dark_Stoner's user avatar
1 vote
3 answers
2k 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 ...
Mr... Gk's user avatar
3 votes
5 answers
3k 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 ...
nath's user avatar
  • 5,804
2 votes
3 answers
7k 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 ...
Mr... Gk's user avatar
0 votes
2 answers
216 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 ...
bjb's user avatar
  • 113
0 votes
1 answer
482 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 ...
Gennadii Prykhodko's user avatar
0 votes
2 answers
321 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 &...
Mykas4ms's user avatar
2 votes
1 answer
605 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 ...
Fabby's user avatar
  • 5,404
2 votes
3 answers
268 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 ...
LazyMark2's user avatar
0 votes
1 answer
139 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 ...
The Chess Artist's user avatar
3 votes
1 answer
1k 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....
Tyson0317's user avatar
1 vote
1 answer
1k 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 ...
ScottishTapWater's user avatar
-5 votes
3 answers
91 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 ...
ntr0v3rt's user avatar
4 votes
1 answer
1k 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*...
watery's user avatar
  • 153
0 votes
1 answer
614 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 ...
nath's user avatar
  • 5,804
0 votes
1 answer
58 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.
lina32's user avatar
  • 47
0 votes
7 answers
2k 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 ...
avi's user avatar
  • 3
12 votes
4 answers
13k 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 ...
piman's user avatar
  • 129
1 vote
0 answers
114 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 (...
alchemy's user avatar
  • 637
0 votes
2 answers
6k 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 ...
pattyboi's user avatar
3 votes
1 answer
83 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 ...
Dan's user avatar
  • 31
2 votes
1 answer
227 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 ° ...
Seamus's user avatar
  • 3,062