tr

What is the `tr` command in Windows?

三世轮回 提交于 2019-12-23 12:01:06
问题 What is the Windows equivalent of the tr command in Linux? For example, tr can replace all colons with a newline character. Can this be done in Windows? $ echo $PATH | tr ':' '\n' /usr/local/bin /usr/bin 回答1: in powershell we have split see this example $a=( echo $env:Path | Out-String ) $a -split ";" before : %SystemRoot%\system32\WindowsPowerShell\v1.0\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System 32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:

How to remove duplicated characters from string in Bash?

我只是一个虾纸丫 提交于 2019-12-22 12:37:12
问题 I have a string cabbagee I want to delete duplicate charaters. If I use tr -s it will remove duplicate characters in the sequence. But my desired output is cabge Appreciate if anyone can help me with that. The answer provided was right but I was not able to use awk so I used: #!/usr/bin/bash key=$1 len=${#key} mkey="" for (( c=0; c<len; c++ )) do tmp=${key:$c:1} echo $mkey | grep $tmp >/dev/null 2>&1 if [ "$?" -eq "0" ]; then echo "Found $tmp in $mkey" else mkey+=$tmp fi done echo $mkey 回答1:

tr command - how to replace the string “\n” with an actual newline (\n)

蹲街弑〆低调 提交于 2019-12-18 13:53:09
问题 I would like to use the tr command to replace all occurrences of the string "\n" with a new line (\n). I tried tr '\\n' '\n' but this just seems to match any '\' and any 'n' 回答1: Here's how to do it with sed : sed 's/\\n/\n/g' Example usage: To replace all occurrences of \n in a file in-place: sed -i 's/\\n/\n/g' input_filename To replace all occurrences of \n through a pipe, and save into another file cat file1 file2 file3 file4 | sed 's/\\n/\n/g' > output_file 来源: https://stackoverflow.com

What does tr -d [=,=] do?

六眼飞鱼酱① 提交于 2019-12-12 21:24:25
问题 I have a code example and there seems to be a piece of extra formatting tacked onto the end of some text processing: tr -d [=,=] I don't know what this does and the man page for tr is of little help. Any insight on what this does? 回答1: From the man tr page, [=equiv=] Equivalence classes The syntax [=C=] expands to all of the characters that are equivalent to C , in no particular order. Equivalence classes are a relatively recent invention intended to support non-English alphabets. But there

remove spaces from cells in matrix

人走茶凉 提交于 2019-12-11 10:00:43
问题 I have a matrix(5800 rows and 350 columns) of numbers. Each cell is either 0 / 0 1 / 1 2 / 2 What is the fastest way to remove all spaces in each cell, to have: 0/0 1/1 2/2 Sed, R, anything that will do it fastest. 回答1: If you are going for efficiency, you should probably use coreutils tr for such a simple task: tr -d ' ' < infile I compared the posted answers against a 300K file, using GNU awk, GNU sed, perl v5.14.2 and GNU coreutils v8.13. The tests were each run 30 times, this is the

tr command in awk to change the column values

点点圈 提交于 2019-12-11 09:48:52
问题 I am using in my shell script TR command in awk to mask the data. Below example file affects only first line of the my file when i used tr command in awk. when i use the same in while loop and called the awk command inside of it then its working fine but it taking very long time to get completed. Now my requirement i want to mask many columns[example :$1, $5, $9] in the same file(file.txt) and this should affect the whole file not first line and i want to achieve this as much as faster to

Remove ^@ Characters in a Unix File

谁都会走 提交于 2019-12-10 14:23:52
问题 I have a question about removing invisible characters which can be only be seen when we try to view the file using "vi" command. We have a file that's being generated by Datastage Application (Source is a DB2 Table -> Target is a .txt File). File has data with different data types. I'm having an issue with just 3 columns which have their datatypes defined as CHAR. If you open the the file in a Textpad you'd see spaces. But when you view the same file on Unix via vi command, we see ^@

tr command not able to direct the Output?

馋奶兔 提交于 2019-12-10 14:18:36
问题 I have got a file file.txt witch has got these entries NY LA SF I ran the command tr '\n' ',' < file.txt and it successfully deleted all of the newline characters. I need all of this output in the same file.txt file, so I redirected the output like this tr '\n' ',' < file.txt > file.txt, but It does not put anything in the file.txt and the resultant file is empty, Can anyone explain to me why the output of tr is getting lost due to redirection. 回答1: because it opens the output file first

How do I split “abcd efgh” into “abcd” and “efgh”?

不问归期 提交于 2019-12-10 11:34:50
问题 This is really self explanatory. I'm working in a bash shell and I'm really new to shell scripting. I've found a lot of information about using tr and sed but all the examples I have found so far are removing delimiters and new lines. I really want to do the opposite of that. I want to be able to separate based on a blank space. I have a string like "abcd efgh" and I need it to be "abcd" "efgh" (all without quotes, just to show groupings). I'm sure this is much simpler than I'm making it, but

Remove matching and previous line

霸气de小男生 提交于 2019-12-07 19:05:37
问题 I need to remove a line containing "not a dynamic executable" and a previous line from a stream using grep, awk, sed or something other. My current working solution would be to tr the entire stream to strip off newlines then replace the newline preceding my match with something else using sed then use tr to add the newlines back in and then use grep -v. I'm somewhat weary of artifacts with this approach, but I don't see how else I can to it at the moment: tr '\n' '|' | sed 's/|\tnot a dynamic