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

Cannot replace multiple whitespaces with one [closed]

I'm trying to remove double spaces and replace them with just one. So far I've tried: sed -i 's/ / /g' ... sed -i 's/[[:space:]][[:space:]]*/ /g' ... tr -s ' ' But none work. Then when I go to the ...
-4
votes
3answers
54 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 ...
3
votes
1answer
94 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*...
0
votes
1answer
35 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 ...
0
votes
1answer
37 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.
0
votes
7answers
78 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 ...
2
votes
4answers
201 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 ...
1
vote
0answers
33 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 (...
-1
votes
2answers
73 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 ...
3
votes
1answer
52 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 ...
2
votes
1answer
69 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 ° ...
0
votes
2answers
54 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 $...
3
votes
0answers
45 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: ...
0
votes
0answers
52 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/^\[.*\] \(.*\)(....
0
votes
2answers
29 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 ...
0
votes
1answer
20 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 ...
0
votes
2answers
51 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 ...
0
votes
3answers
101 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/...
8
votes
2answers
1k 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 "\'\\\"\?\!"...
0
votes
2answers
75 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' <&...
0
votes
1answer
158 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 ...
-2
votes
4answers
293 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; ...
1
vote
3answers
666 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. “...
0
votes
1answer
47 views

Multiline Variable add a Tab before each Newline

The Following snippet uses a custom function HexNewLine which basically converts the hexdump and breaks at the character 0x0a $ echo -e "\t{ > "dependencies": { > "prettier": { > ...
0
votes
3answers
70 views

How to change and list a file containing lines with the following format : XXX-XXX-XXX-XXX-XXX

For example, let's say I have a file "athletes" with the lines 1995-05-30-John-Smith 1992-John-30-Smith-10 How could I list the first 2 words of the lines that end in "Smith" and the last one, ...
1
vote
2answers
67 views

format output with what?

I'm trying to format the output from the following command; MYIP=(/sbin/ifconfig $(getnic) | awk '/inet/ { print $2 } ' | sed -e s/addr://); echo $MYIP which generates the following output; 172....
1
vote
1answer
51 views

Replace each letter in a .txt with the letter six positions later

I want to "encrypt" a .txt by replacing each letter with the letter six positions later. What I have right now is: tr [:alpha:] ??? < myfile.txt But I don't know what to put in ??? ... Any help ...
0
votes
1answer
100 views

Why does `tr` not work with find and with command substitution? [duplicate]

I want to transform/"translate" all files in a folder from lower to uppercase. I could use a for loop to do that: for i in ./* ; do mv $i $(echo $i | tr "a-z" "A-Z") ; done for i in `find . -maxdepth ...
5
votes
2answers
2k views

Is there any way to use the tr command in place?

I want to remove all non-english alphanumerals from a file. tr -sc '[:alnum:][:punct:]' ' ' <file gawk and sed have the -i flag but I cannot find anything similar in the tr man pages. How can I ...
0
votes
2answers
135 views

Unable to simply use tr to convert a tab-delimited-variable file to a comma-delimited-variable file

Regarding this txt file, which is best described as a tab-delimited .txt file with empty lines between rows containing content: One would think that running cat goods.txt | tr "\t" "," > output....
2
votes
0answers
68 views

How to grep an eternal string coming from STDIN

Using bash i'm trying to grep a string coming from /dev/urandom something like this: tr -cd '[:lower:]' < /dev/urandom | grep -o 'test' Also tried: tr -cd '[:lower:]' < /dev/urandom | grep -o ...
0
votes
2answers
50 views

Joining a standard output and susbtitution thereof into table

Say I have: $ cat tmp1.txt a b c Then $ paste tmp1.txt <(tr '[:lower:]' '[:upper:]'<tmp1.txt) a A b B c C How would I modify the above to 1/ invoke tmp1.txt only once? (I suspect tee)...
3
votes
6answers
1k views

Linux tr to convert vertical text to horizontal

I've been reading about https://stackoverflow.com/questions/39791042/convert-vertical-text-into-horizontal-in-shell and wondering if tr alone can be used to convert vertical text to horizontal. user@...
1
vote
2answers
594 views

find n most frequent words in txt file using the terminal but with the cat, “grep .” and tr -d “/r” commands

I would like to find n most common words in a text file but with the following conditions: cat to get the file. grep . to get the words. tr -d '/r' to get rid of new lines. I've managed to get ...
0
votes
1answer
359 views

Remove punctuation except a particular symbol in a particular position

I'm using tr to parse text and do several tasks like lower-case all words, remove punctuation and multiple spaces. The end result should be clean lower-case text with only alpha-numeric characters, ...
18
votes
3answers
3k views

What do the dots in this tr command do: tr …A-Z A-ZA-Z <<< “JVPQBOV” (with 13 dots)

I want to use tr to do some rot13 transformation. I can beautifully understand this command: tr A-Za-z N-ZA-Mn-za-m <<< "URYC ZR CYRNFR" which output is HELP ME PLEASE, but I can't figure ...
7
votes
1answer
338 views

Is it possible to replace duplicates of a character with one character using tr

I'm trying to take all occurrences of # and if they are consecutive replace them with just one #. e.g. ab ### cde fghi## jklm would become: ab # cde, fghi# jklm My initial goal was to replace ...
0
votes
1answer
750 views

How to replace double new line with single using tr?

Given a text, $ cat a.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor vitae. Etiam iaculis ...
8
votes
2answers
1k views

Explanation needed on how I can repeat a character in POSIX shell

The following answer on Stack Overflow, How can I repeat a character in bash? imposes one plausible way of POSIX-ly repeating a single character, as follows. In this example let's use the equal sign ...
3
votes
3answers
759 views

Replacing all instances of string containing hyphen

Running the following command: echo "hello-world" | tr "hello-world" "Hello World" Returns Heddd-ddddd. I want it to return Hello World. I believe this is because tr is interpreting the SET1 ...
0
votes
1answer
981 views

Removing unseen junk characters from the file in unix

I am trying to remove unseen junk characters from the file which can be seen using cat -v . I got the script below in google but i am curious to know how the below command works . tr -cd '\11\12\40-\...
-1
votes
2answers
52 views

Subtract string value in col1 from col2 and populate col2

I have a data file that looks like this: MASTER APP SET STATUS max_mstr_ref max_mstr_ref_horizon_biz pp_script true max_mstr_ref ...
0
votes
1answer
115 views

replace first semicolon occurence

Hi I have a logfile and I want to replace the first semicolon occurence, like: head1;head2;head3;head4;head5 blabb;blabl;;blab;blabl;;bla Desired output: head1;head2;head3;head4;head5 blabb;...
2
votes
4answers
2k views

How to concatanate the result of two Linux commands

Is there an easy way to concatenate the result of two Linux commands, in one line (i.e., without using variables)? I pull the local outdoor temperature from a nearby weather station. The result ...
0
votes
3answers
96 views

adding a new line character to a row

I'd like to extract the 2nd field and transpose it to become a row cat > temp1 1 73 2 74 3 75 My approach : cut -f2 temp1 | tr '\n' '\t' > temp2 The result : temp2 73 74 75 ...
0
votes
2answers
2k views

sed: remove extra whitespace to single whitespace between strings while leaving leading tabs intact

I have a code: 1 /** 2 a b c 3 **/ 4 int main() { 5 int x; 6 if ( condition) { 7 return x; 8 } 9 } I need to change multiple whitespaces between ...
-2
votes
3answers
687 views

Change all but first ',' to “<COMMA>” for each row in file (bash) [duplicate]

I am using bash and have a csv file (dat.csv) that needs to be only two columns (App, Blurb) of data but due to many ',' on each row it is becoming MANY columns. EXAMPLE OF PROBLEM csv.dat: App , ...
0
votes
1answer
49 views

How to delete whitespaces in columns?

I want to filter some columns of a file, it has 46 in total. I only want to filter from the 25 until the 46, by the next way: Desired Output: Column25 Column26 ... Column47 Column25 Column26 ... ...
2
votes
4answers
94 views

How to reformat named.conf's zone blocks into single lines?

For reasons I won't go into here, I need to make a copy of an old CentOS 5.10 server's named.conf file and perform some text manipulation on the copy. The final result should consolidate each zone's ...
0
votes
4answers
94 views

make row to column n insert newline in every last row

i have file.txt john, 5901, open lina, 2401, open jody, 5401, open I want to insert a new line every last row, The result should be : john,5901,open lina,2401,open jody,5401,open what i try ...