Ascii to caracter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ascii to caracter
# 1  
Old 02-21-2008
Ascii to caracter

Hi,

I'm trying to get from "a" to "b". So far, I've been able to get the ascii code for "a" and from there to get the code for "b". But, and this is were I'm stuck, I can't find how to show the symbol associated with the code I calculated. This is what I have right now

Code:
test=a
valeur=`printf %u "'$test"`
char=`expr $valeur + 1`
printf %c $char

It outputs "9" and I want to get "b"
# 2  
Old 02-21-2008
Hammer & Screwdriver use the tr function

>echo "g" | tr '[a-y]' '[b-z]'
>h

or

>trchar="j"
>echo $trchar | tr '[a-y]' '[b-z]'
>k

This would work for 25 letters of the alphabet
# 3  
Old 02-21-2008
I changed you code little bit to try and I get the following output
Quote:
test=a
valeur=`printf %u "$test"`
char=`expr $valeur + 1`
#printf %c $char "\n"
printf "$char \n"
printf "\\$char \n"
Quote:
98
P
printf "\<ascii number>" gives the ascii character for that value.
The "valeur" is taking the value of 97.
I assumed the value of "A" is 65.
When I run the following command in ksh I get the value of A as 101
Quote:
cat /usr/share/lib/pub/ascii
I have no idea why I'm getting the weird output

Last edited by bobbygsk; 02-21-2008 at 07:09 PM..
# 4  
Old 02-22-2008
This is really too much to do in a shell. But this works...
Code:
$ cat nextchar
#! /usr/bin/ksh

while : ; do
        printf "enter a character - "
        read char
        printf "this char is %c \n" $char
        val=$(printf "%c" $char | od -An -td1)
        printf "decimal value is %d \n" $val
        printf "octal value is %o \n" $val
        ((val=val+1))
        octal=$(printf "0%o" $val)
        nextchar=$(echo \\${octal})
        printf "next char is %c \n" $nextchar
done
$ ./nextchar
enter a character - a
this char is a
decimal value is 97
octal value is 141
next char is b
enter a character - A
this char is A
decimal value is 65
octal value is 101
next char is B
enter a character - 1
this char is 1
decimal value is 49
octal value is 61
next char is 2
enter a character - !
this char is !
decimal value is 33
octal value is 41
next char is "
enter a character - ^C
$

To run this in bash, you probably need to change the echo or set the xpg_echo option.
# 5  
Old 02-22-2008
Thanks everyone for your suggestions.

I tried joeyg's solution and it works. I'm probably going to use it since it's pretty simple and I'm not the one who will be using this.

I'm taking good note of your code though Perderabo, for personal comprehension Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

2. Shell Programming and Scripting

bash ascii

hi guys In my bash script I need to use ascii characters such as SYN(22) and US(31). How do I echo them? (3 Replies)
Discussion started by: vlm
3 Replies

3. Programming

Hexadecimal to ascii

Let's suppose i have a hexadecimal array with 16 cells.for example b3e2d5f636111780 i want to convert it to an array of ascii characters(in C) so that i can reduce total size of the file i want to put it in. But i am afraid i have not fully understand the difference between ascii and hex(i... (3 Replies)
Discussion started by: bashuser2
3 Replies

4. Shell Programming and Scripting

Delete a line last caracter

Hello dears, I have a CVS file in wich a have many lines. each line is ended by this two caracters ';;'. I want to get a new format of this file by deleting this caracters which unix shell script eg. of input file: a;b;c;d;; a;b;c;; a;b;; a;b;c;d;e;; That means each line lenght can... (2 Replies)
Discussion started by: yeclota
2 Replies

5. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

6. Shell Programming and Scripting

binary to ascii

Hi, Is there a way to convert the binary file to ascii . the binary file is pipe delimited. from source the file(pipe delimited) is ftped to mainframe and from mainframe it is ftped to the unix box using binary format. Is there a way to change it back to ascii and view it? Thanks! (3 Replies)
Discussion started by: dnat
3 Replies

7. Shell Programming and Scripting

code ASCII for Caracter -->> '

I'm a question: the expresiion 'expr $a +1' use the caracter --> ' (is not shift+ ? !!!) what is the code ascii for generate this caracter ?????? tank's (3 Replies)
Discussion started by: ZINGARO
3 Replies

8. Programming

Extended ascii

Hi all, I would like to change the extended ascii code ( 128 - 255). I tried to change LC_ALL and LANG in current session ( values from locale -a) and for no good. Thanks. (0 Replies)
Discussion started by: avis
0 Replies

9. UNIX for Dummies Questions & Answers

ascii

a silly question but is there a way to display individual ascii values say if i type 65 it will display the letter instead? thanks fo any help. (3 Replies)
Discussion started by: melkor
3 Replies

10. UNIX Desktop Questions & Answers

ASCII file

I've been having trouble trying to read an ASCII file. I'm on an IRIX machine, by the way. I've tried "cat" and I get a bunch of unreadable text, and the "string" command gets the "Command not Found" error. Please advise. Thanks. (1 Reply)
Discussion started by: sherbet808
1 Replies
Login or Register to Ask a Question