How to get ascii value using shell commands/script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get ascii value using shell commands/script
# 1  
Old 12-15-2008
Bug How to get ascii value using shell commands/script

Hi gurus,

Need command/code to get the ASCII value for a character say 65 for A and vice versa in shell script.

Thanks in advance
# 2  
Old 12-15-2008
Quote:
Originally Posted by kittu1979
Need command/code to get the ASCII value for a character say 65 for A and vice versa in shell script.

Code:
## Character to ASCII
printf "%d\n" "'A"

## ASCII number to character
awk -v char=65 'BEGIN { printf "%c\n", char; exit }'


Last edited by cfajohnson; 12-15-2008 at 04:23 PM..
# 3  
Old 12-15-2008
Hammer & Screwdriver What about

Code:
> echo "A" | tr -d "\n" | od -An -t dC
   65
> echo "X" | tr -d "\n" | od -An -t dC
   88
> echo "a" | tr -d "\n" | od -An -t dC
   97

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Two exec commands in one shell script?

Hi Folks - Is there a way to add two execs to one script? For instance, I need to redirect the stdout and stderr to two separate directories. I want to do this: #::-- Direct STDOUT and STDERROR to repositories --::# exec 2>"${_ERRORFILE}" > "${_LOGFILE}" exec 2>"/new/path/file.err" >... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

2. UNIX for Dummies Questions & Answers

Commands to run from shell script

Hi script> isumid 98765432 if i give above command in cmd prompt it is running the same thing if i give inside the shell script it is not working below is the code #!/bin/bash isumid 98765432 please give me a solution (16 Replies)
Discussion started by: Ramrangasamy
16 Replies

3. Shell Programming and Scripting

Linux commands in shell script?

I am trying to learn to write basic shell scripts. I have a little experience with perl but none with shell. I am trying to write a simple script to write the last 15 or so lines of log files for my web server to a temp file so I can view all at once. Here's what I have. Are you not able to use... (6 Replies)
Discussion started by: ktb231
6 Replies

4. Shell Programming and Scripting

Using Ex editor commands in a shell script - Help!

Hi all, I am trying to use the Ex editor and its commands in a script - more specifically within an if statement within a while loop. Here are the basics of the loop: cat $file1 | while read line do grep $line $file2 if ] then echo $line > $file2 elseex $file2 /ESI185... (4 Replies)
Discussion started by: luke222010
4 Replies

5. UNIX for Dummies Questions & Answers

How to use a Shell Script for specific commands

I have a set of commands that I am using to copy specific areas of source code in a Cold Fusion document and export the code into recreations of the original files into a sub-directory. Here are the 3 commands I am using: mkdir ./out && for x in *.cfm; do awk '{FS="<!-- InstanceBeginEditable... (17 Replies)
Discussion started by: dratech09
17 Replies

6. Shell Programming and Scripting

writing a shell script of commands

Can anyone help me out in visualizing on what is the logic behind simple unix commands. For Eg: ls command lists files and directories, how it displays I need to know the source code for commands like this. (1 Reply)
Discussion started by: rahul_11d
1 Replies

7. Shell Programming and Scripting

Why can't embed commands like fg or bg in a shell script ?

Hi Can someone explain in an easy way that why can't embed commands like fg or bg in a shell script ? (4 Replies)
Discussion started by: qiulang
4 Replies

8. Shell Programming and Scripting

shell script to run a few commands help!

Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u I need to write a shell script which will run the following commands pg_dump bank > backup(Enter) Wait for bash prompt to appear coz it indicates that the command is... (23 Replies)
Discussion started by: perk_bud
23 Replies

9. Shell Programming and Scripting

how to sql commands in shell script

hi, plz let me know one example in using sql command in shell script thanks inadvance -bali. (1 Reply)
Discussion started by: balireddy_77
1 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question