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
# 8  
Old 04-07-2016
I showed you how to do that. Read the input as a string, and examine each character in the string using substrings, and if the character has an ord() value less then 46, convert the character to the chr (ord()+16). Then output the string one character at a time, or create a new string to process.
# 9  
Old 04-07-2016
i tried the give loop by jgt but it is not working in unix and perl

Last edited by Don Cragun; 04-07-2016 at 11:54 PM.. Reason: Add mission ICODE tags.
# 10  
Old 04-07-2016
What jgt posted was pseudocode, not actual code. Pseudocode is used to demonstrate coding principles
# 11  
Old 04-08-2016
I don't code much in perl, but this seems to do what you want using awk:
Code:
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"
}
{	printf("Processing:%s--->", $0)
	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 ""
}' file

which, if file contains the sample input you provided in post #1 in this thread, produces the output:
Code:
Processing:11500#.0#--->1150035.035
Processing:28575$.5$--->2857536.536
Processing:527#.7#--->52735.735
Processing:42".2"--->4234.234
Processing:2794 .4--->279432.4
Processing:2279!.9!--->227933.933
Processing:1067&.7&--->106738.738
Processing:926#.6#--->92635.635
Processing:2279!.9!--->227933.933
Processing:885".5"--->88534.534
Processing:11714$.4$--->1171436.436
Processing:27361'.1'--->2736139.139
Processing:2%.2%--->237.237
Processing:533".3"--->53334.334

As always, if someone wants to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
# 12  
Old 04-08-2016
Please, someone enlighten me: WHAT is an "overpunch character"?
This User Gave Thanks to RudiC For This Post:
# 13  
Old 04-08-2016
Found this:
https://en.wikipedia.org/wiki/Punche...haracter_codes
and
https://en.wikipedia.org/wiki/Signed_overpunch

Last edited by Scrutinizer; 04-08-2016 at 05:40 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 14  
Old 04-08-2016
Thanks, should have searched myself. That's not the way the term is used in here, no?
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