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:
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
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.
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:
)!@#$%^&*( <- 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:
#!/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.
Thanks again Don , but still it pending
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.
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";
}