Questions tagged [tr]
21 questions
10
votes
2 answers
How does tr translate one word to another?
I have a file ma.txt and it contains the output of ls -l; when I run the tr command (tr "nik-pc" "root") I get this output:
nik-pc@nik:~$ cat ma.txt
total 52
drwxr-xr-x 2 nik-pc nik-pc 4096 Mar 11 11:33 Desktop
lrwxrwxrwx 1 nik-pc nik-pc 2 Mar …
Manish Bharti
- 341
9
votes
2 answers
How can I add a backslash before all spaces?
How can I put a backslash before every space, preferably by using tr or sed commands?
Here is my script:
#!/bin/bash
line="hello bye"
echo $line | tr ' ' "\\\ "
This is supposed to replace spaces with a backslash followed by a space, but it's only…
olfek
- 1,353
9
votes
4 answers
How would you separate fields with multiple spaces and store them in an array?
In my file mytxt:
field1 field2
------ -------
this are numbers 12345
this letters abc def ghi
Let's say I want to store the first field in an array:
i=0
while read line; do
…
zou hai
- 101
7
votes
1 answer
tr: command not found
I'm using Ubuntu 18.04, and recently I keep getting this error when running bash scripts: tr: command not found. The tr does not exists in /usr/bin and /usr/sbin. Also installed coreutils but still no luck. How can I add this command to my…
4
votes
3 answers
How I can count how many repeated numbers in a file and then organize them by repetitions?
I have a file that needs organized a number of repeats, my file has 6 rows and 3120 lines each member has 1 or 2 digits, total 18720 numbers with one or 2 digits.
I would like to count how many 1, how many 2, how many 3 so on to how many 45 I have…
John
- 171
2
votes
2 answers
Looping tr command to remove '\r' in multiple files in a directory
I have about 260 files in a directory. How can I input these files one by one into some thing like this
file is an array name
file=input stream of multiple files
x=0
LOOP
tr -d '\r' file2
rm $file
mv file2 $file
x=$x+1
LOOP ends
SamFlynn
- 1,025
2
votes
2 answers
Why does tr "\oo" " " not replace the "\" character?
I ran echo "\oo" | tr "\oo" " ", and the output is:
\
\o is not a special character, like \n, so why is the \ not converted into a space too?
paperangel220
- 710
2
votes
2 answers
How to split string in TSV file
I have TSV file like this:
abc_1
def_2
ghi_3
jkl_4
mno_5
I want to split that in to the:
abc
def
ghi
jkl
mno
and
1
2
3
4
5
How I can get that?
Lulu' Nisrina
- 39
- 7
2
votes
1 answer
How can I use tr command using more than 2 arguments?
I want to replace a-l letters with m-z letters and m-z characters with a-l in text file using tr command. (a is replaced with m, b with n, c with o, m with a, b with n, etc.) I tried `tr a-l m-z | tr m-z a-l but it replaces a-l letters with m-z…
xpol78
- 23
2
votes
3 answers
CSV to TSV without replacing commas within quotes
All the CSV to TSV tutorials are suggesting a simple:
tr ',' '\t'
though some CSVs look like this:
1,310,"IntAct,PINA"
in which case I would like to keep "IntAct,PINA":
1 310 "IntAct,PINA"
How could I parameterize the tr command (or sed, etc.)…
tr3quart1sta
- 339
1
vote
1 answer
Using the tr command with character ranges
For the past few months, I've been learning about the command line with the help of William E. Shotts' The Linux Command Line.
The Linux Command Line remains a popular book for newbies who would like to learn more about the Linux command line.
In…
1
vote
4 answers
Remove Control Return and merge lines in one text file and limit number of characters
I wan to remove Control Return and merge lines in one text file and limit number of characters
input.txt containing:
comment 1
comment 2
...
comment n
output.txt should one strings:
comment 1 comment 2 ... commnet n
BUT the ouput.txt should be…
Confluentes Info
- 107
1
vote
1 answer
Ubuntu Server 14.04.3 update problems
using Ubuntu Server 14.04.3. apt-update & upgrade stuck on tr.archive.ubuntu.com
It's responding so slow and can't download packages.
Adil Börekçiler
- 11
- 1
1
vote
2 answers
Why can't I remove spaces using tr -s
When I enter the following:
echo "This is for testing" | tr -s [:space:]
I get this:
This is for testing
I was hoping to remove the multiple spaces and just have one space between the words. I don't see what I am doing wrong.
daveh
- 91
1
vote
3 answers
delete empty lines
I could need some help with a oneline script im building. The script should give me a list of services, which are running on the current system. I wanted to realize this with systemctl.
The current oneliner looks like this:
systemctl list-units…
Paradice
- 13