hi. I have a requirement where I need to REPLACE all alphabets from an alphanumeric input string into their respective ASCII decimal value. For example:
If the input string is ABAC123 , the output should be 65666567123
I am seeking a single line command, and I was trying searching for options of TR command.
Hi R. Singh,
Note that the output kumarjt wants to produce contains no spaces and only translates alphabetic characters (leaving numeric input characters unchanged) producing ambiguous output when numeric characters are included in the input .
With kumarjt's specified behavior, the output from both of the following input strings: ABCA653 and ABCAA3 is the same string 65666765653 .
Hi kumarjt,
The tr utility translates one character to one character, it does not translate a single character to a pair of characters.
So above command will look for only alphabets and convert them into their ASCII their values with printing digits values as it is.
EDIT: Adding a non-one liner form of above solution too now.
Of all the replies, Don Cragun's has been the eye opener for me.
I thank all of you for the support, but the actuality is ABCA653 and ABCAA3
needs to be handled seperately even if the expected command evaluates to the same numerical value, which is 65666567123 .
Let me brief you my business requirement, which I can manifest only to the slightest amount.
these alphanumeric strings are portfolio#'s, and we are receiving multiple files for each portfolio#, and we are required to always move files for each folio into the same folder.
We have to distribute all folio files in a round robin manner into 3 folders and all files for ABCA653 should be moved into a single folder, and similarly for ABCAA3 , but these two are totally different folio#.
Thank you for letting me know here. So following are the 2 solutions.
I- Which will work for a variable as per OP's request.
II- Where we could pass an Input_file to it.
Solution 1st:
Thanks for the help disedorgue. Just the thing I wanted.....
But, can this one liner be acheived by any other command than PERL?
The reason for asking so is in our project, we've not used/abstained from using PERL so far.