Convert Overpunch character values to number that comes between the numbers in perl

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Convert Overpunch character values to number that comes between the numbers in perl
# 1  
Old 04-07-2016
Convert Overpunch character values to number that comes between the numbers in perl

I have variable that contains multiple values of number and also includeOverpunch character so we want to replace it with numbers.
here are the example:
Code:
11500#.0#
28575$.5$
527#.7#
42".2"
2794 .4
2279!.9!
1067&.7&
926#.6#
2279!.9!
885".5"
11714$.4$
27361'.1'
2%.2%
533".3"

could you please help me out.
# 2  
Old 04-07-2016
What have you tried so far?
# 3  
Old 04-07-2016
I used ord function but it is working for single special character.not able to covert above value.
# 4  
Old 04-07-2016
It looks like you need to add 16 to the ascii value of each special character.
That is assuming that a space is zero, and a ) is 9.
In pseudo code
Code:
a=input string
for i=1 to len(a)
if asc(substr(a,i,1)) <48
  echo chr(asc(substr(a,i,1)+16)
else
  echo substr(a,i,1)
fi
next i

where asc("0") is 48 and chr(48) is "0".
Slight adjustment, a decimal point is 46 so line 3 should be <46 not <48

Last edited by jgt; 04-07-2016 at 12:17 PM..
# 5  
Old 04-07-2016
Hi jgt- It didnt work, I want to change ascii character to number that is between the numbers in all rows.
Code:
11500#.0#
28575$.5$

# 6  
Old 04-07-2016
PHP has the chr and ord (asc) functions.
What did you write?
# 7  
Old 04-07-2016
jgt- I am working with perl on linux env. we can convert single value with the help of .
Code:
$ascii_value = ord("%");
print 'cii_value'.$ascii_value;

it print: cii_value37
but i need to find and replace a column value that can different ascii values. so in this it is not working.
like-- $ascii_value = ord("886%.6%"); then output : 56
but i need 88637.637 -- this correct. Please help on this

Last edited by Don Cragun; 04-07-2016 at 11:53 PM.. Reason: Add missing CODE and ICODE tags again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert list of numbers to text range

Hi, I'd like to take a list of numbers (with a prefix) and convert to a range, for example: cn001 cn004 cn016 cn017 cn018 cn019 cn020 cn021 cn031 cn032 cn038 cn042 cn043 cn044 cn045 (5 Replies)
Discussion started by: chrissycc
5 Replies

2. UNIX for Beginners Questions & Answers

Convert ascii character values to number that comes between the numbers in UNIX

I have variable that contains multiple values of number and also include overpunch(i.e. # $ % etc) character so we want to replace it with numbers. here are the example: Code: 11500#.0# 28575$.5$ 527#.7# 42".2" 2794 .4 2279!.9! 1067&.7& 926#.6# 2279!.9! 885".5" 11714$.4$ 27361'.1'... (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies

3. Shell Programming and Scripting

Convert Column Values to a Range of Values

I have a list of columns with values that I need to transform into a row containing the range of each column. For example: "Column A" 1 2 3 4 10 12 14 15 16 17 18 "Column B" 1 4 5 6 (4 Replies)
Discussion started by: newbio
4 Replies

4. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

5. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

6. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies

7. Shell Programming and Scripting

How to convert hex numbers to decimal ?

Hi, please tell me how to convert hex number to decimal 000000E7 000000000002640D 0000000000025B16 and seconds to minutes, hours, days, months, years bytes to kbytes, mbytes , gbytes read the following examples while read a b do printf "%5d %5d\n" "0x$a" "0x$b" done < "$FILE"... (15 Replies)
Discussion started by: jack2
15 Replies

8. UNIX for Dummies Questions & Answers

How to Convert Strings into Numbers under C-Shell?

I tried something like: set test3 = (4.985e-10 5.130e-10 5.486e-10 6.023e-10 7.015e-10) set test4 = (4.869e-10 5.010-10 5.363e-10 5.895e-10 6.887e-10) set test5 = $test3 - $test4 but this doesn't seem to work. And then I tried: @ test5 = $test3 - $test4 This doesn't seem to work... (8 Replies)
Discussion started by: EDALBNUG
8 Replies

9. UNIX for Advanced & Expert Users

Req on how to convert hex numbers to decimals

Hi, If i have an input as c1:41 c2:0x0000.00046b3e I want to make output display as c1:41 c2:224062 . Basically convert first part 0x0000 (as hex) to decimal which is 0 and convert second part 0x00046b3e (as hex) to decimal which is 289598 and as such add both parts namely... (3 Replies)
Discussion started by: hare
3 Replies

10. Shell Programming and Scripting

hw can i count the number of character in a file by perl

i want to count the number of character contained in afile using perl cript help me out (1 Reply)
Discussion started by: trupti_rinku
1 Replies
Login or Register to Ask a Question