translate or delete characters

learn more… | top users | synonyms

8
votes
5answers
460 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
51 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 'à', ...
8
votes
4answers
562 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
369 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 '\' ...
9
votes
3answers
2k 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
133 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 ...
4
votes
2answers
899 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
390 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
95 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
2k 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
224 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 ...
3
votes
4answers
921 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
71 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 ...
7
votes
2answers
1k 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
284 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? ...
1
vote
4answers
256 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
2
votes
4answers
2k 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
274 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
994 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 ...
-1
votes
1answer
760 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
49 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
558 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
4k 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
807 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
615 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
486 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
411 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 ...
8
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 ...
0
votes
2answers
498 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, ...
6
votes
2answers
20k 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 != ...
3
votes
2answers
614 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?
1
vote
1answer
833 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 ...
3
votes
2answers
941 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 ...
4
votes
3answers
653 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 ...
2
votes
3answers
1k 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;. ...