help needed with ASCII conversion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help needed with ASCII conversion
# 1  
Old 08-17-2009
help needed with ASCII conversion

I have a file say "codefile" here ,contains data like this

Hi! How are you?

I need to covert this data into stram of equivalant ASCII values

I wrote follwoing script.

#!/bin/bash
while read -n1 char
do
printf "%d" \'$char
done < codefile

this gives me output

./coder.sh
7210533072111119097114101012111111763


it has printed sapaces as 0 (Blue coded) which is suppesed to be 32(equivalant ACSII for space)

Please help

-S
# 2  
Old 08-17-2009
Add quotes round the $char in your printf
# 3  
Old 08-17-2009
Quote:
Originally Posted by Smiling Dragon
Add quotes round the $char in your printf

I added

#!/bin/bash
while read -n1 char
do
printf "%d" \'"$char"
done < codefile

------------------------------
But no change in output ,tried adding $"char" also but no go.

./coder.sh
72105330721111190971141010121111117630

Smilie
# 4  
Old 08-17-2009
Hmm, adding the quotes allows a space to be converted (before that it was treating it as null)
But the read is also turning the space characters into nulls (to see this, add echo "\"$char\"" before your printf).
So, we'll switch to using something else like cut:
Code:
#!/bin/bash
while read line
do
        while [ -n "$line" ]
        do
                char=`echo "$line" | cut -c1`
                line=`echo "$line" | cut -c2-`
                #echo "\"$char\""
                printf "%d" \'"$char"
                #echo ""
        done
done < codefile

# 5  
Old 08-17-2009
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

Continue here:

https://www.unix.com/shell-programmin...onversion.html

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

EBCDIC to ASCII conversion

Hi, We have a mainframe file which is in EBCDIC format.We dont have direct access to mainframe ,client has provided us the mainframe file.The mainframe file is containing pact data(COMP1 ,COMP2 etc) which are unreadble.Can anyone suggest me how to convert this kind of ebcdic file to ascii... (11 Replies)
Discussion started by: swapna_1990
11 Replies

2. UNIX for Advanced & Expert Users

EBCDIC to ASCII conversion

Hi, I have a input file which is EBCIDIC and it has packed decimals. Can anyone help me to convert EBCIDIC file to ASCII(Need to convert even Packed decimal values also to normal format). Thanks swapna (12 Replies)
Discussion started by: swapna_1990
12 Replies

3. UNIX for Advanced & Expert Users

Conversion from EBCDIC to Ascii OR unicode

I have a file in my Unix ( SOLARIS ) with EBCDIC format...I want this file to read in ASCII OR unicode...Is it possible with UNIX to convert this file on ASCII OR UNICODE format from EBCDIC format? I was searching through web and found only conversion table :( Request Rejected Below is... (16 Replies)
Discussion started by: joshilalit2004
16 Replies

4. Shell Programming and Scripting

ASCII to UTF-8 conversion

I Am trying to change the file encoding from ASCII to UTF-8 using below command iconv -f ASCII -t UTF-8 <input_file> > <output_file> But the output_file is not actually in UTF-8 format. If I use the file command to check the file encoding it still says ASCII. While converting am not... (5 Replies)
Discussion started by: Sriranga
5 Replies

5. Shell Programming and Scripting

binary to ascii conversion

Hi, I have got a library file, created by compiling C code. The file information with "file" command, gives it a "application/x-archive" type file. I want to extract the release string of my software from this file, so that i can know which version of C files were used to create the lib. Can... (3 Replies)
Discussion started by: atulmt
3 Replies

6. UNIX for Dummies Questions & Answers

Conversion from EBCDIC to ASCII

when i try to convert a mainframe EBCDIC file to ASCII ,i dont see correct file this is the source file ... (3 Replies)
Discussion started by: venkatvelpula
3 Replies

7. Shell Programming and Scripting

need help with ascii to decimal conversion

Hi, Can anyone please help me ascci to decimal conversion in bash I have a file which contains stream of numbers like this,these are ascci values 729711810132973278105991013268971213233 I want to covert it to its actual value like upper code's decimal is "Have a Nice Day!" ... (15 Replies)
Discussion started by: sunilmenhdiratt
15 Replies

8. UNIX for Advanced & Expert Users

File conversion to ascii

Hi All, I have a data file which has binary and hexa decimal data..i tried to convert that file using dd and od commands but i am getting some numbers and junk values... Please let me know is there any other command which can convert this file to ascill. Awaiting your responses -Mora (4 Replies)
Discussion started by: mora
4 Replies

9. Shell Programming and Scripting

ascii to ebcdic conversion

Hello, I need a program for ascii to ebsdic conversion. If anybody can help, it'll be greatly appreciated. Thanks. (1 Reply)
Discussion started by: er_ashu
1 Replies

10. Shell Programming and Scripting

ascii conversion

after converting my ebcidic file to ascii i get the following output 2097152+0 records in 1797345+1 records out Why is there a difference in number of records. Is the converson chopping off any records. All i am doing is just a conversion using the following script dd if=xaa cbs=152 ... (0 Replies)
Discussion started by: rintingtong
0 Replies
Login or Register to Ask a Question