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.

chr()
{
  ## convert number to ASCII character
  printf "%b\n" $(printf '\x%x\n' "$@" 2>/dev/null)
}

Thanks for your reply johnson....

Can you please explain me more on this... chr().... please explain the code written... if possible with an example...

John I forgot to mention few things.....

Our file contains so many multibyte characters also...

File have lots of records... and the data will be like below..

Ascii values ---> 67 97 110 97 100 97

When i give above thing as input ... it should print like below...

characters ---- > Canada

Please suggest a solution.

Could you please post a sample record.
However, here is an another approch to convert the ascii value to character

echo "65" | awk '{ printf("%c",$0); }'  # output will be A

Try this:

awk '{ for(i=1;i<=NF;i++) printf("%c",$i); print "";  }'  filename

Thanks for your reply....

Its is working fine...

My file looks like..... one record will have nearly 1000 ascii values.... like that 20000 records are there

When i use above given code it is prompting some message like

awk: record `34 124 34 34 124 34 6...' has too many fields

Please help me out.....

Try this:

awk '{n=split($0,a)
  for(i=1;i<=n;i++){
    printf("%c",a)
  }
}
{print ""}
' file

Regards

Its working perfectly ... thank you....

i am getting bigger ascii values also like 49457 ... these are not converting.... any solution for this ...

ASCII values are defined to be - 0...127, 8 bit "ASCII" 0...255, which is usually called UTF-8 If you have values larger than 255, you are dealing with something other than ASCII.

Are you sure the number 49457 is correct? Something is not right here.

Thanks jim.

Actually we are getting korean and china characters along with french characters in the file which is received in unix. when we are receiving the file with ascii values, values are getting bigger like 54356 some thing like this because of korean characters.

Please suggest me a solution regarding this.. on how to hold korean characters and china characters in unix and load to database.