translate or delete characters

learn more… | top users | synonyms

8
votes
3answers
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
3answers
189 views

Help with tr command

Assume that the file ft has 25 lines of text. Explain the command: tail -15 ft | tr "a" "A" > ft and tell me how many lines the file ft has after the execution of the command. I understand that ...
0
votes
1answer
29 views

Delete Non numeric row from a csv

I have used sed to allow only numeric and csv format ,I have used sed '/[^0-9, -, .]/d' as regex. It has still "_","1-0","1-1" character as o/p which worries me. sed 's/'"$(printf '\015')"'//g' ...
4
votes
4answers
926 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 ...
0
votes
1answer
65 views

Sed command for performance improvement or tr command for the same

I have a command to replace the non printable characters and single quotes from a file but its taking more time to execute as I am replacing these characters for multiple files and the files size is ...
0
votes
0answers
15 views

Dictionary - synonyms

I have czech czech-finnish dictionary and I have two czech synonyms in one row. Example: záchod (m); toaleta (f) WC; käymälä; miestenhuone; naistenhuone; vessa Synonyms are divided by semicolon ...
27
votes
3answers
37k 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? ...
9
votes
5answers
10k 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
164 views

Debian wheezy updates broke tr command [closed]

After I updated the following packages yesterday in debian wheezy, tr command stop working. Start-Date: 2016-02-16 23:10:06 Commandline: apt-get dist-upgrade Upgrade: libkrb5-3:amd64 ...
17
votes
5answers
23k 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: ...
2
votes
4answers
655 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
0
votes
1answer
381 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" < ...
12
votes
1answer
745 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 "Латвийская" ...
1
vote
2answers
112 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
47 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 ...
0
votes
2answers
106 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
103 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 ...
11
votes
5answers
22k 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 ...
5
votes
2answers
350 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 ...
1
vote
4answers
113 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
1answer
109 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 ...
2
votes
2answers
118 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
70 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
171 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
58 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
53 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. ...
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. ...
16
votes
4answers
8k 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 ...
3
votes
4answers
274 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
2answers
7k 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
1answer
78 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. ...
8
votes
2answers
8k 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
2answers
96 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
384 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
604 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:]' ...
4
votes
5answers
464 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 ...
0
votes
2answers
658 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
vote
1answer
195 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 'à', ...
1
vote
2answers
5k 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 '\' ...
3
votes
3answers
179 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
4k 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 ...
6
votes
1answer
139 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, ...
3
votes
4answers
633 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 ...
2
votes
1answer
468 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 ...
4
votes
1answer
112 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 ...
4
votes
3answers
384 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? ...
3
votes
4answers
7k 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
539 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 ...
1
vote
1answer
3k 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 ...