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
# 15  
Old 04-08-2016
Great answer don !! but can u please tell how we can pass variable one by one into this command instead of passing file.
# 16  
Old 04-08-2016
Hi RudiC and Scrutinizer,
Using the term overpunch, I first thought of Hollerith cards as well. Then I assumed that nadeemrafikhan was referring to characters that appear on the numeric keys on the keyboard with the shift key held down:
Code:
)!@#$%^&*(  <- Characters on shifted numeric keys
0123456789  <- Characters on numeric keys

but the <single-quote> and <double-quote> characters don't fit that pattern either.

Hi nadeemrafikhan,
What do you mean by "overpunch character"?

Perhaps you want something like:
Code:
#!/bin/ksh
while read -r input
do	result=$(printf '%s\n' "$input" | awk '
	BEGIN {	a = "\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17" \
		    "\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37" \
		    " !\"#$%&\47()*+,-./0123456789:;<=>?@" \
		    "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" \
		    "abcdefghijklmnopqrstuvwxyz{|}~\177"
	}
	{	for(i = 1; i <= length($0); i++)
			if((c = substr($0, i, 1)) ~ /[0-9.]/)
				printf("%s", c)
			else	printf("%d", index(a, c))
		print ""
	}')
	printf 'Processing:%s-->%s\n' "$input" "$result"
done < file

which, when run by a POSIX-conforming shell, produces exactly the same output as my earlier suggestion, but runs slower and consumes more system resources.

Last edited by Don Cragun; 04-08-2016 at 10:09 AM.. Reason: Fix typo: missing space: s/"!\"#$/" !\"#$/
# 17  
Old 04-08-2016
Well, I thought of old printers: print a char, backspace, overpunch, but that was mayhap a vocabulary problem...

Quote:
Originally Posted by Don Cragun
.
.
.
Code:
)!@#$%^&*(  <- Characters on shifted numeric keys
0123456789  <- Characters on numeric keys

but the <single-quote> and <double-quote> characters don't fit that pattern either.
.
.
.
That's different depending on the local keyboard type. German kbd:
Code:
 ! " § $ % & / ( ) = 
 1 2 3 4 5 6 7 8 9 0

BTW, that's part of the problem we (I !) non-ascii people have quick typing some *nix standard chars like / , | , and \ .
# 18  
Old 04-08-2016
Thanks again Don , but still it pending Smilie
let me show you how I am doing it.
I have this data
0002178#
0001008(
0000886%
and I know what would be the overpunch character because i extract it from substr function.

Code:
if ($f !~ /^\d+$/ )
{
$camount=substr($line,23,8);--this is the vulue like 0002178,0001008,0000886
$vovrpunch=ord("$f");  --- getting the overpunch value but it is sending me wrong
$var3 = $camount.$vovrpunch;
$ltwodgt = substr($var3,-2);
$var3 =~ s/\d{2}$//;
$camnt=$var3.".".$ltwodgt;
$camnt =~ s/^0+//;
#print "$damnt\n";
}

value that are coming:
2178.35
1008.40
886.37

but the correct values are:

217.83
100.88
88.65

Could you please help me on this Smilie
# 19  
Old 04-08-2016
Code:
number=`echo $string |sed -e script`

#where script is
Code:
 
s/ /0/g
s/\!/1/g
s/\"/2/g
s/\#/3/g
s/\$/4/g
s/\%/5/g
s/\&/6/g
s/\'/7/g
s/\(/8/g
s/\)/9/g

Somehow some of the digits in the input have been changed to characters 16 ascii positions lower in the character set.

---------- Post updated at 01:01 PM ---------- Previous update was at 12:53 PM ----------

Think of it as a Florida election where some of the chad stays in row 4 in 8 channel paper tape.
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