translate or delete characters

learn more… | top users | synonyms

1
vote
2answers
73 views

how to substitute minus sign with tr

I'm trying to replace several symbols with spaces, and I thought tr was the right command. So I tried cat myfile | tr '_[]()-/' ' ' But I get the error range-endpoints of ']-/' are in reverse ...
2
votes
3answers
43 views

how to extract a number from the line in unix

I need to find the first occurrence of the attribute ICount and its value must be returned. Only the number from the attribute. How to get it? < FCount = "1" ICount = "0" Ccount= "1"> Please ...
1
vote
2answers
91 views

How to display each day of a month on a separate line using tr, sed and cal

How to use commands, cal, sed and tr and the pipe to display the numerical days (e.g., 1, 2, 3, etc.) of a month, with each day on a separate line I've tried: cal 12 2015| sed '3,7p' | tr -cs ...
0
votes
1answer
52 views

Delete lines beginning and ending with a digit

I thought this was easy even for a beginner like me, but I'm stuck - piping a text file like this: cat file1.txt | sed '/^[0-9].*[0-9]$/d' > file2.txt This regex catches the lines in a text ...
5
votes
2answers
259 views

What's the difference between `-C` and `-c` in `tr` command?

Today I learnt a bit about tr command. But I was stuck at understanding the difference between -c and -C. On the manual, it said: -C Complement the set of characters in string1, that is ``-C ...
2
votes
1answer
75 views

tr -c '[a-zA-Z]' '\n' not replacing all complement characters

Writting a script I wanted to replace all characters except alpha ([a-zA-Z]) with a line break. By definition, when using -c flag (set complement) tr is supposed to replace all characters that are not ...
1
vote
4answers
72 views

How to get the number of each punctuation mark from a file

grep '[".?!"]' Returns the lines that have one of these but I have no clue how to tell how many are in each line, let alone how many ., ?, and ! there are.
2
votes
2answers
86 views

Can I disable buffering for tr

tr seems to buffer its input so that this command LongRunningCommand|tr \\n , will only start producing output after a few kilobytes of input from LongRunningCommand have accumulated. Is there a way ...
0
votes
1answer
46 views

Remove trailing spaces from first field only

I have a multi-lined, tab-delimited file like this: 99999bbbbbt999999bbt99t99t99t99 (where b=spaces, t=tabs) Trailing spaces in the 2nd field are ok, but the trailing spaces in the 1st field need ...
4
votes
6answers
153 views

Make longer strings from substrings keeping new line between each string

I have a file that contains strings as: GTACGACGGAGTGTTATAAGATGGGAAATCGGATACCAGATGAAATTGTGGATCGGTGCAAAA GTCGGCAGATATCGTTGAAGTCATAGGTGATTATGTTCAATTAAAGAAGCAAGGCCGAAACTAC ...
0
votes
3answers
43 views

Remove character from string at specific location

This seems too easy but still can't get it work. I have: -X-1.5 and need: -X1.5 Using: echo -X-1.5 | tr -d '-' gives: X1.5 which it's close, but not close enough. Any pointers are ...
2
votes
2answers
48 views

why my first pipe operation didn't remove newline character?

My nextermCensus.lis contains newline character and I am only interested in the first line, I'd like to remove newline character. but it doesn't work. so I have to use second method to remove it. ...
11
votes
1answer
261 views

How to make tr aware of non-ascii(unicode) characters?

I'm trying to remove some characters from file(UTF-8). I'm using tr for this purpose: tr -cs '[[:alpha:][:space:]]' ' ' <testdata.dat File contains some foreign characters (like "Латвийская" ...
3
votes
4answers
203 views

To remove newlines after empty line

Data 4. Alendronic acid A. Antiosteoporotic agent. B. Inhibit osteoclast formation and function by inhibiting FPPS enzyme, so increase bone mass. C. Osteoporosis in combination with vitamin D. ...
0
votes
1answer
304 views

How to terminate cat command within a shell script

I wrote a shell script that uses cat and tr commands to generate a file. My shell script looks like #!/bin/bash printf "generating random file > plaintext \n" cat -v | tr "a-z" "b-y" < ...
0
votes
1answer
73 views

What does $'text' do exactly in Bash? Can it be used in Zsh?

I recently run into the following proposed solution: cat results.csv | tr $'\x01' \\t > result.csv to convert a malformed csv file (one that uses \x01 unicode as a separator) into a correct one. ...
1
vote
2answers
81 views

How to only leave in given characters in a file?

Purpose: tr -cd '\12\40-\176' but with accents, ex.: á, í, ű, ő, ö, ü, ű, ú, ó, é. In octal: "á" is 341 "\n" is 12 So I tried: [user@notebook ~]$ printf 'XXXá\nXXX' | tr -cd '\12\341' | ...
0
votes
4answers
288 views

How does “-dc” work in “cat /dev/urandom | tr -dc ”01"?

So far I know, the /dev/urandom file is one of the special files, it's purpose is to generate random characters. When I execute cat /dev/urandom a stream of strange characters, some even Chinese ...
5
votes
3answers
448 views

Can tr commands be chained to avoid multiple tr processes in a pipeline?

I have a bunch of txt files, I'd like to output them lower-cased, only alphabetic and one word-per line, I can do it with several tr commands in a pipeline like this: tr -d '[:punct:]' ...
21
votes
5answers
3k views

Generating a random password; why isn't this portable?

I want to generate a random password, and am doing it like so: </dev/urandom tr -dc [:print:] | head -c 64 On my laptop, which runs Ubuntu, this produces only printable characters, as intended. ...
4
votes
5answers
388 views

how to split file and lines

I have a text file like : 1_01 { ; quite good spirals reset=2000 type=mandel passes=1 corners=-0.6014129278/-0.5990935452/0.427747516/0.429487053 params=0/0 float=y ...
15
votes
5answers
14k views

Convert file contents to lower case

I have temp file with some lower-case and upper-case contents. Input Contents of my temp file: hi Jigar GANDHI jiga I want to convert all upper to lower. Command I tried the following command: ...
1
vote
1answer
173 views

Telling 'tr' that a-z is not only ASCII

tr -sc 'A-Za-z' '\012' is what I need, but it doesn't include all letters. How can you make this work for languages like French? How can you tell 'tr' that among 'a-z' there should also be an 'à', ...
10
votes
5answers
16k views

How do I remove spaces from shell variables?

I have done the following at command line: $ text="name with space" $ echo $text name with space I am trying to use tr -d ' ' to remove the spaces and have a result of: namewithspace I've tried ...
1
vote
2answers
3k views

How do I suppress a warning message?

touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\') 2> /dev/null where foo is a directory It's reading the full pathname of foo and creating it as a file replacing all '/' with '\' ...
23
votes
3answers
27k views

Replace multiple spaces with one using 'tr' only

I have a file, f1.txt: ID Name 1 a 2 b 3 g 6 f The number of spaces is not fixed. What is the best way to replace all the white spaces with one space using only tr? ...
3
votes
3answers
174 views

“Tuning” tr and sed expression

I have MD5 file which lists filename and MD5 sum in the following way: MD5 (file14n0001.xml.gz) = 04eb2524d271077ec8f1a0021779b171 MD5 (file14n0002.xml.gz) = 07e2b29645e9211cce9daf1ae27e7b99 MD5 ...
8
votes
2answers
7k views

tr complains of “Illegal byte sequence”

I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands. I am attempting to use tr and grep so that I can search for text strings in a regular ...
0
votes
2answers
5k views

Fastest & Most Core way to replace “\r\n” with “\n” in a file?

I suppose tr is a more core method and thus probably a faster way to replace things within a given file. However tr can only replace equal amounts of characters. meaning... 2 characters can only be ...
6
votes
1answer
130 views

Heirloom Toolchest tr: error(s) trying to delete the complement of a set containing a multibyte character?

I'm trying to use the tr command from the Heirloom Toolchest to overcome a current limitation of the coreutils implementation, so as to be able to "pump" (with the -dc options) multibyte characters ...
3
votes
2answers
3k views

How can I print out all but the last n characters in bash?

I'm working with standard input (cating two files together) and want all but the last 10 characters of the result to be passed through the next command. All I can find through searching is using sed, ...
2
votes
1answer
409 views

Counting consecutive repetitions of a specific character (e.g. ,)

Say I have a file with lines like the two following: foo,bar,,baz,xy foo,,bar,baz,xy,, I would like to count how many times I have ,, (two consecutive commas surrounded by any other character) in ...
7
votes
4answers
7k views

Replace all newlines to space except the last

How can I replace all newlines with space except the last newline. I can replace all newline to space using tr but how I can do it with some exceptions?
4
votes
1answer
108 views

Is the historical Unix V5 tr command padding behavior of set2 different from what we consider today “classic” System V (1983-1988) behavior?

The tr command is almost 40 years old. It seemingly appeared in Unix for the first time in 1973 with Unix V4. The source for this is not available. Here is probably the second oldest available Unix ...
8
votes
2answers
3k views

Removing non printable characters from expect logs?

How can I either strip the following character sequences from my files? ^[[64;8H, ^[[?25h, ^[[1;64r etc or avoid having expect add them in the first place? Background: I'm using a collection of ...
4
votes
3answers
352 views

how to emulate “replace a b b a” with a sed?

I am trying to emulate a replace command which swaps two characters, with a sed script, but the obvious choice: sed -e 's/a/b/g' -e 's/b/a/g' does no work. Can you point me how to do it correctly? ...
2
votes
4answers
583 views

How to change color of a character while tailing and tr

I regularly use this command line but I would like to change the color of the "|" to green in the output. Does anyone know how I can accomplish this? tail -f file.log | tr '\001' '|' | grep TEST
3
votes
4answers
6k views

Can tr work with regex?

I have a file like this: AAAA BBBB CCCC DDDD etc Words in separate lines. I want to add them quotes using tr. So I tried the following: 1) To add a quote in the start of each word ...
3
votes
1answer
488 views

Why does this one-liner clobber files?

I have written this to help me batch-encode some videos: find -name '*.mkv' -exec HandBrakeCLI -Z "Android Tablet" \ -c "1-3" -m -O --x264-tune film -E copy --decomb -s 1 -i {} \ -o `echo {} | tr ...
6
votes
2answers
2k views

How to convert UTF-8 txt files to all uppercase in bash?

I have some UTF-8 .txt files which I would like to convert to all uppercase. If it was just ASCII, I could use: tr [:lower:] [:upper:] But since I'm working with diacritics and stuff, it doesn't ...
0
votes
1answer
2k views

Delete only first occurrence of character using tr

I want to delete the occurrence of a character in a string only for the first occurrence. Example: echo "B123_BACK" | tr -d 'B' This results in output: 123_ACK How can I delete only the first ...
2
votes
1answer
69 views

understanding the difference between “-C” and “-c” in tr(1) utility

According to tr(1) manual -C means: Complement the set of characters in string1, that is ``-C ab'' includes every character except for `a' and `b'. ..and -c means: Same as -C but complement the ...
-1
votes
1answer
1k views

using tr -t command [comprehension question]

When using tr -t command, string1 should be truncated to the length of string2, right? tr -t abcdefghijklmn 123 # abc... = string1, 123 = string2 the cellar is the safest place # actual ...
2
votes
4answers
7k views

print last field from line + alternative for awk

Due to technical reason on my Solaris machine, I can't use awk in order to print the last field in line. What are the other alternatives to awk that print the last field from line (using cut or tr ...
1
vote
1answer
1k views

tr command not working with octal sequences

I need to strip non-ASCII characters off a file. I was using the command - /usr/xpg4/bin/tr -cd '\0-\177' <non-ASCII_file.dat >ASCII_file.dat Though it worked in the past, it is not ...
1
vote
2answers
1k views

Redirecting tr stdout to a file [duplicate]

Possible Duplicate: How can I make iconv replace the input file with the converted output? Can I read and write to the same file in Linux without overwriting it? $ cat test.txt This is a ...
3
votes
1answer
864 views

tr not replacing apostrophe

I want to convert all apostrophes in this file to X: Bob's book Bob’s book Bob′s book # (Might look the same but actually different) The first apostrophe is replaced as expected: $ cat file | tr ...
3
votes
4answers
576 views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
15
votes
4answers
7k views

Why can't tr read from /dev/urandom on OSX?

A colleague suggested creating a random key via the following command: tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c 32 | xargs It gave me the error: tr: Illegal byte ...
0
votes
2answers
625 views

Removing a long string from php files - using grep and sed?

I have encountered some malware on my Linux server, and am trying to remove it from many php files. I've tried endlessly with grep | sed and grep | tr and couldn't even erase a simple text string, ...