translate or delete characters

learn more… | top users | synonyms

8
votes
3answers
371 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? ...
7
votes
3answers
4k 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 ...
6
votes
1answer
70 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 ...
6
votes
2answers
668 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 ...
5
votes
2answers
15k views

Removing all spaces, tabs, newlines, etc from a variable?

This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel). I am getting spaces in that variable. + 0 != ...
5
votes
2answers
666 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 ...
4
votes
3answers
268 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? ...
4
votes
3answers
599 views

How do I delete all lines with “.png” in a file?

I've a list of urls of which some point to images: http://s.thebrighttag.com/iframe?c=A5lqOqP ...
4
votes
1answer
58 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 ...
3
votes
2answers
625 views

How does tr '[a-z]' '[n-za-m]' work?

I found an obfuscated e-mail address that can be decrypted using this command: echo "cbyrzba@cbyrzba.bet" | tr '[a-z]' '[n-za-m]' How does that output a valid e-mail address? What is that command ...
3
votes
4answers
364 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 ...
3
votes
4answers
319 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?
3
votes
1answer
207 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 ...
3
votes
3answers
123 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 ...
3
votes
2answers
536 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, ...
3
votes
1answer
404 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
2answers
440 views

what is the benefit of --squeeze-repeats in tr command

What is the benefit of -s or --squeeze-repeats when we use tr? What practical usage?
2
votes
1answer
148 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 ...
2
votes
4answers
3k 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 ...
2
votes
3answers
937 views

Is there a tr for translating into longer strings?

tr is great for translating a set of characters to another set of characters. Sometimes, I want to translate a set of characters to a set of strings, e.g. all < and > to &lt; and &gt;. ...
2
votes
1answer
47 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 ...
2
votes
2answers
89 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 ...
1
vote
4answers
200 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
1
vote
4answers
1k 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 ...
1
vote
2answers
51 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 '\' ...
1
vote
1answer
612 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
1answer
779 views

Diff similar lines

I'd like to print a list of lines where the first word in two files is identical, and the rest of the words are not. Some complicated mess with comm, grep and cut would be possible, but hopefully ...
1
vote
2answers
322 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 ...
0
votes
2answers
50 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 ...
0
votes
2answers
463 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, ...
-1
votes
1answer
438 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 ...
-1
votes
1answer
420 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 ...