Questions tagged [tr]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
2 answers
1k views

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 ...
daveh's user avatar
  • 71
0 votes
1 answer
108 views

Trying to create a file to meet three conditions

I need to make a file that lists the first 5 lines of the /sbin directory, with having all 5 lines numbered AND all lines capitalized. Here is one string of commands that I tried: tr [a-z] [A-Z] < ...
RetroActive's user avatar
0 votes
1 answer
812 views

How to replace every 2nd line sed

How to replace every 2nd line of a text file with another text file list of lines. Example: cat filea.txt I love Pink I love Blue I love Dogs I love MOMO cat bileb.txt I hate yello I hate white I ...
Pooja Jha's user avatar
2 votes
2 answers
1k views

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?
user1046658's user avatar
1 vote
3 answers
1k views

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 ...
Paradice's user avatar
2 votes
2 answers
1k views

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's user avatar
2 votes
1 answer
2k views

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 ...
xpol78's user avatar
  • 23
0 votes
0 answers
703 views

How can I remove null and ctrl+m characters from a CSV file?

I have a CSV file that starts with NULL bytes that come from Hive Beeline CLI query output. The file starts with many lines that have ^Mnull^Mnull in the first lines: ^Mnull ...
Omer Anisfeld's user avatar
9 votes
4 answers
5k views

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 ...
zou hai's user avatar
  • 101
1 vote
1 answer
106 views

Change characters to lowercase

I am trying to make all values in the 11th column of my .csv file lowercase. I know I can use 'tr A-Z a-z' but how do I make sure it is working in the file I want and only on the 11th column.
Justin Quinlisk's user avatar
2 votes
3 answers
595 views

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 ...
tr3quart1sta's user avatar
7 votes
1 answer
6k views

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 ...
saman.shahmohamadi's user avatar
0 votes
0 answers
203 views

Condition on the output to xterm of a variable that has been echo'ed in color

The fourth line of this code outputs the input argument in green color to an xterm. However, I'd like to be able to condition on the value of the input. If I input the word Foo then from bash's ...
Leo Simon's user avatar
  • 1,519
1 vote
1 answer
665 views

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 ...
John_Patrick_Mason's user avatar
1 vote
3 answers
3k views

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 ...
Confluentes Info's user avatar
0 votes
1 answer
77 views

Testing the limits of the tr command using character ranges

I'm trying to test the limits of the tr command using character ranges. What I don't get is how come I get the output: lowercase letters when typing: echo "lowercase letters" | tr A-Z A-Z instead ...
John_Patrick_Mason's user avatar
10 votes
2 answers
6k views

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 ...
Manish Bharti's user avatar
1 vote
1 answer
70 views

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's user avatar
4 votes
3 answers
3k views

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, ...
John's user avatar
  • 171
2 votes
2 answers
4k views

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 ...
SamFlynn's user avatar
  • 995
9 votes
2 answers
39k views

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 ...
olfek's user avatar
  • 1,295