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.
193 questions
-1
votes
1
answer
111
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 &...
-1
votes
2
answers
7k
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 ...
2
votes
0
answers
137
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'...
0
votes
1
answer
125
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 ...
5
votes
1
answer
476
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" ...
0
votes
2
answers
240
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 ...
0
votes
1
answer
256
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 ...
5
votes
3
answers
631
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 ...
0
votes
5
answers
900
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 ...
6
votes
1
answer
4k
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 ...
0
votes
0
answers
39
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,...
0
votes
1
answer
300
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 +...
3
votes
2
answers
780
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 ...
2
votes
2
answers
1k
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-...
2
votes
1
answer
248
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 ...