Questions tagged [tr]

translate or delete characters

Filter by
Sorted by
Tagged with
0
votes
2answers
30 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
77 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 ...
0
votes
3answers
131 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
144 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
20 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
59 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
54 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
43 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
50 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 ...
2
votes
2answers
689 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
67 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....
1
vote
0answers
62 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
49 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)...
2
votes
6answers
799 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
364 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
232 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
2k 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
318 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
654 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
631 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 ...
4
votes
3answers
415 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
612 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
49 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
91 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
1k 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
86 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
921 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
507 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
47 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
62 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
81 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 ...
3
votes
1answer
412 views

Remove multiple strings from file on command line, high performance [closed]

Is there an elegant, high-performance one-liner way to remove multiple complete strings from an input? I process large text files, e.g., 1 million lines in inputfile, and 100k matching strings in ...
10
votes
2answers
1k views

Strange behaviour of tr using ranges

I have one particular server that is exhibiting strange behaviour when using tr. Here is an example from a working server: -bash-3.2$ echo "abcdefghijklmnopqrstuvwxyz1234567890"|tr -d [a-z] ...
1
vote
2answers
56 views

Compile list of words from list of files

How would one take on this task? I've tried to do it with tr, and come up with this (with help of other similar question): tr -c '[:alnum:]' '[\n*]' < long_concatenated_file but.. Its a bit of a ...
3
votes
5answers
213 views

Split text in specific order using common string “Message”

I have a text file with following contents $ cat foo.txt some text email@id.com 8903457923 2018-02-09 07:12 (Asia/Kolkata) again some text over here some more text again Message some text email@id....
2
votes
1answer
315 views

I cannot understand what -c parameter does in tr command in Ubuntu GNU/Linux even though I read the manual

I try to understand what -c option does in tr command according to man tr command it says: -c, -C, --complement use the complement of SET1 But I cannot understad what the doc mean ...
1
vote
1answer
5k views

Using tr to replace text with repeated characters

I tried using tr to replace a variable name in a file, and I noticed some behavior I can't figure out if the variable has a repeated character. For example: echo "aab" | tr 'aab' 'xyz' gives the ...
1
vote
1answer
256 views

How does the “1<>file” shell input/output redirection work?

I saw this piece of code on another question, but I wasn‘t able to comment on the answer so I‘m asking here. tr '\n' '\0' < file 1<> file I‘m interested in the 1<> part, never seen ...
2
votes
1answer
804 views

How to translate Unicode characters? [duplicate]

I'm trying to convert some characters to the fullwidth form like this tr 'abcdefghijklmnopqrstuvwxyz' 'abcdefghijklmnopqrstuvwxyz' However, it doesn't work. I did a search and it turns out tr doesn'...
4
votes
3answers
5k views

Main difference between tr (translate) to sed and awk

AFAIC both sed and awk are general purpose text processing utilities with whom a user can get quite similar results, in a slightly different syntax: With both, a user could add, replace/translate and ...
9
votes
1answer
860 views

tr a A < /etc/hosts | sort -r |pr -d > /etc/hosts

In this line: tr a A < /etc/hosts | sort -r |pr -d > /etc/hosts what would be the expected outcome? I know lowercase 'a' would change to uppercase 'A' but what's next? Would the original file ...
0
votes
3answers
90 views

Can anyone explain to me how this script works?

I was looking for a script that changes the filename and directory name to lowercase and replaces any white spaces with "-". I managed to find the script below inside another script but I do not fully ...
1
vote
1answer
207 views

invalid source string in KSH but not in BASH

I try to generate a random string using this command: tr -dc 'A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c16; echo; I need to put that command into a function ...
6
votes
5answers
4k views

Replace any number of tabs and spaces with single new line in Linux? [closed]

I have a very large word list that has been damaged, maybe by improper vim exit or memory exhaustion? Everything in my word list should be left-justified. But now it is like this: Cat ...
14
votes
3answers
4k views

Can I use `sed` to translate characters like with `tr`?

I would like to replace a set of characters with corresponding characters from another set, something like this: original set: ots "target" set: u.x foobartest → fuubar.ex. Translations/...
7
votes
3answers
2k views

tr analog for unicode characters?

I need internationalized utility that does the same thing as tr: gets character from stream and substitutes it with a corresponding character. Not a particular case solution like lower-to-upper, but a ...
1
vote
1answer
569 views

Why does tr -sc 'A-Za-z' '[\12*]' includes empty line?

I'm working through Unix For Poets, and trying make a file containing all words/tokens in the Bible. However, when using tr, as suggested, this includes the empty string. See example below: > tr -...
0
votes
3answers
3k views

Remove spaces between two words ONLY

I have the following "/x/x y/asfas/g.pdf " "fdfdf "/x/y/yy y/d.doc " "fdfdf etc.. I want to remove the spaces between the extension and the " ONLY when I used tr to remove trailing ...
3
votes
1answer
56 views

How to prefix backslash to output [duplicate]

This is my input file. 3400,2 3400,27 3400,DC 3400,TF 5600,KA 5600,KN 5600,TF 0313,EX 0313,EY 0313,EZ 0313,FD 0313,FE 0313,JB 0313,JC 0313,KG 0313,T8 I want my output to be 400,2\|3400,27\|3400,DC\|...
1
vote
2answers
1k views

how to use tr to delete a octal characters sequence?

I'm trying to delete this: --More-- from a .dat file, this is a fragment of the file to give an example: Device ID: N7K-LAN(JAF1651ANDL) IP address: 148.228.4.192 Interface: GigabitEthernet0/1,...