i want to use tr to remove all the lowercase characters from a string and replace them with a '.', i can't seem to get it to work, heres an example of what im trying, someone please correct me
If the current directory contains file(s) with a name formed by a signle lowercase character the shell will substitute [a-z] by the file list.
Jean-Pierre.
If the current directory contains file(s) with a name formed by a signle lowercase character the shell will substitute [a-z] by the file list.
Jean-Pierre.
Yeah, but even with those quotes, there are still problems. tr varies quite a bit from system to system. And, as per tradition, the orignal poster provided no clues about his version of unix. According to the Posix Standard
Quote:
c-c
In the POSIX locale, this construct shall represent the range of collating elements between the range endpoints (as long as neither endpoint is an octal sequence of the form \octal), inclusive, as defined by the collation sequence. The characters or collating elements in the range shall be placed in the array in ascending collation sequence. If the second endpoint precedes the starting endpoint in the collation sequence, it is unspecified whether the range of collating elements is empty, or this construct is treated as invalid. In locales other than the POSIX locale, this construct has unspecified behavior.
So if the tr program is following the standard, you will convert [ and ] into periods for sure. And if the locale is set to Posix, the lower case letters will also be converted into periods as well. There are still some non-standard version of tr that require '[a-z]' for a range and treat 'a-z' as 3 characters. Among the tr programs that accept a-z, there are two behaviors for '[a-z]':
[a-z] == a-z
[a-z] == ]a-z[
with the second being what the standard requires. With a non-standard locale, the author of the locale determines what a-z means. The confusion over a-z verses [a-z] arises from the fact that BSD used a-z and System V used [a-z]. Posix had to pick one and the went with BSD. Apparently not everyone was happy with choice and compliance with this requirement is not universal.
Now that we have discussed the difficulty with the first parameter, let's look at the second parameter. We have a second System V/BSD clash and this time Posix wimped out. Whatever the first parameter means it is more than one character but the second parameter is guaranteed to be only one character. So the strings are not equal in length. According to the standard:
Quote:
When string2 is shorter than string1, a difference results between historical System V and BSD systems. A BSD system pads string2 with the last character found in string2. Thus, it is possible to do the following:
tr 0123456789 d
which would translate all digits to the letter 'd'. Since this area is specifically unspecified in this volume of IEEE Std 1003.1-2001, both the BSD and System V behaviors are allowed, but a conforming application cannot rely on the BSD behavior. It would have to code the example in the following way:
tr 0123456789 '[d*]'
So, to do exactly what the author intended,
tr '[a-z]' .
requires both the System V behavior or ignoring (or requiring) brackets around a range (a Posix violation) and BSD's "extend the last character of a shorter string" behavior (not guaranteed by Posix). A more correct solution is:
tr '[:lower:]' '[.*]'
but now you probably see why I prefer sed for something like this...
hey, well i didn't expect my post to ellicit this much discussion i was just tearing my hair out because i thought that my command:
Quote:
echo $var | tr [a-z] .
should have been converting all of the lowercase chars to . What was happening which was confusing me so much, was that it was only converting the first lowercase char in the string, so it seemed like i was missing some obvious command, i tried all combinations of quotes etc and even misinformedly tried putting brackets around the . -> [.] :P the version of unix i was working on was solaris and the bourne shell, don't know if that helps explain anything, but im grateful for the help and have the solution already in place thanks again
Cheers!
In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not?
To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
I had a script in solaris wich i read data, for example:
Number 1: _
and the cursor use to be in '_' place because in the code of the script i write:
echo "Number 1:\c"
but i copy the script to a linux and the cursor 'jump' to the begining of the next line like:
Number 1:... (2 Replies)
Hi Guys,
I've been learning UNIX for the past couple of days and I came across this exercise, I can't get my head around it, so I would be ever so grateful if I could receive some sort of help or direction with this.
Create a file with x amount of lines in it, the content of your choice. ... (3 Replies)
Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
I'm new to unix commands and am wondering how you could create a page with html tags in it. echo "<b>Test</b>" > test.html doesn't work because of the tags. How would I do this. (4 Replies)
Can anyone tell me if there is a way to remove the encryption from Data CDs by UNIX? Or does anyone know of a program that can remove the encryption?
I would much appreciate it!
Thanks,
-Peaves (2 Replies)
I have a problem, why should root access only be provided from a login on the console, and why should a user be forced to use "su" command to perform system maintenance, rather than logging in? (2 Replies)
Friends,
I did following exercise
$ echo '' > test
$ od -b test
$ echo "">test
$ od -b test
$echo > test
$od -b test
Every time I got the following output
0000000 012
0000001
But 012 is octal value for new line character .
Even though there is no apperent new line character... (6 Replies)