Sponsored Content
Top Forums Programming I don't know how to replace input char with appropriate integer Post 302563019 by durden_tyler on Sunday 9th of October 2011 10:05:43 PM
Old 10-09-2011
Quote:
Originally Posted by solaris_user
...
Program must convert input character to approriate number, if you have a close look then you shell see program traslates american style of phone to numeric.

For example if I enter 1-800-COL-LECT
then output must be 1-800-265-5328
...
Code:
$
$
$
$ echo "1-800-COL-LECT" | perl -MPOSIX -lne 'while(/(.)/g) {$d = uc($1);
                                               if (grep /$d/, ("A".."Z")) {
                                                 $x = (grep /$d/, qw(S V Y Z)) ? 0 : 1;
                                                 $num .= (ceil((ord($d)-64)/3) + $x);
                                               } else {$num .= $1}
                                             }
                                             print $num'
1-800-265-5328
$
$
$
$ echo "1-800-col-lect" | perl -MPOSIX -lne 'while(/(.)/g) {$d = uc($1);
                                               if (grep /$d/, ("A".."Z")) {
                                                 $x = (grep /$d/, qw(S V Y Z)) ? 0 : 1;
                                                 $num .= (ceil((ord($d)-64)/3) + $x);
                                               } else {$num .= $1}
                                             }
                                             print $num'
1-800-265-5328
$
$
$
$ echo "1-800-ASK-USPS" | perl -MPOSIX -lne 'while(/(.)/g) {$d = uc($1);
                                               if (grep /$d/, ("A".."Z")) {
                                                 $x = (grep /$d/, qw(S V Y Z)) ? 0 : 1;
                                                 $num .= (ceil((ord($d)-64)/3) + $x);
                                               } else {$num .= $1}
                                             }
                                             print $num'
1-800-275-8777
$
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Don't show keyboard input on terminal

I am developing a script that will run with '/bin/ksh' shell. The script is intended to receive a password by keyboard input, but for security reasons I would like to hide what the user is typing. The keyboard input is being caught by 'read' command. exmaple : echo "Please type your new... (1 Reply)
Discussion started by: marianor31
1 Replies

2. Shell Programming and Scripting

Replace floating-point by integer in awk

Hi, I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format... Geometry "geometry" -> "geometry" 1 Pd 46.0000 -0.19290971 0.00535260 0.02297606 2 P ... (7 Replies)
Discussion started by: smadonald1
7 Replies

3. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

4. UNIX for Advanced & Expert Users

test the string is char or integer

How will test the string contains numeric character or alphabet, is there any script to test ? (10 Replies)
Discussion started by: rajesh08
10 Replies

5. Programming

to compare two integer values stored in char pointers

How can I compare two integer values which is stored in char pointers? suppose I have char *a and char *b having values 10 and 20. how can i find the shorter value? (1 Reply)
Discussion started by: naan
1 Replies

6. Programming

How i can read a long integer from standar input and a string with as many characters as specified..

how i can read a long integer from standar input and a string with as many characters as specified in the number? i thing that i must use the read command ofcourse.... (6 Replies)
Discussion started by: aintour
6 Replies

7. UNIX for Dummies Questions & Answers

Input of char 's' is not possible anymore

Hello, I have a big problem and no idea how to solve it. I was looking up commands in /bin with 'man' as I found 'sh'. In mistake I started the command. Now after that I can not input the character 's' in shell anymore! Even after restarting system the problem is still there. Mysterious... (7 Replies)
Discussion started by: daWonderer
7 Replies

8. UNIX for Dummies Questions & Answers

Check if input is an integer or a floating point?

Hiii I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ? Thanking you (2 Replies)
Discussion started by: krishnampkkm
2 Replies

9. Shell Programming and Scripting

Using IF statements with maths where the input is not an integer

Hi All I've made a few scripts which using GDAL extract the value of a pixel within a given raster. The purpose is to work out the combine value of every pixel. I thought there may have been an easier way to do this but alas! The code below extracts the pixel value at position X Y. The... (3 Replies)
Discussion started by: StudentFitz
3 Replies

10. UNIX Desktop Questions & Answers

awk a integer and replace it minus X

hey, i have a list of devices that looks like so: VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(358271365120608989UL))),Option<ulong>())))),2098560),... (5 Replies)
Discussion started by: boaz733
5 Replies
Simple action in tc(8)                                                 Linux                                                Simple action in tc(8)

NAME
simple - basic example action SYNOPSIS
tc ... action simple [ sdata STRING ] [ index INDEX ] [ CONTROL ] CONTROL := { reclassify | pipe | drop | continue | ok } DESCRIPTION
This is a pedagogical example rather than an actually useful action. Upon every access, it prints the given STRING which may be of arbi- trary length. OPTIONS
sdata STRING The actual string to print. index INDEX Optional action index value. CONTROL Indicate how tc should proceed after executing the action. For a description of the possible CONTROL values, see tc-actions(8). EXAMPLES
The following example makes the kernel yell "Incoming ICMP!" every time it sees an incoming ICMP on eth0. Steps are: 1) Add an ingress qdisc point to eth0 2) Start a chain on ingress of eth0 that first matches ICMP then invokes the simple action to shout. 3) display stats and show that no packet has been seen by the action 4) Send one ping packet to google (expect to receive a response back) 5) grep the logs to see the logged message 6) display stats again and observe increment by 1 hadi@noma1:$ tc qdisc add dev eth0 ingress hadi@noma1:$tc filter add dev eth0 parent ffff: protocol ip prio 5 u32 match ip protocol 1 0xff flowid 1:1 action simple sdata "Incoming ICMP" hadi@noma1:$ sudo tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 match 00010000/00ff0000 at 8 action order 1: Simple <Incoming ICMP> index 4 ref 1 bind 1 installed 29 sec used 29 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 hadi@noma1$ ping -c 1 www.google.ca PING www.google.ca (74.125.225.120) 56(84) bytes of data. 64 bytes from ord08s08-in-f24.1e100.net (74.125.225.120): icmp_req=1 ttl=53 time=31.3 ms --- www.google.ca ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 31.316/31.316/31.316/0.000 ms hadi@noma1$ dmesg | grep simple [135354.473951] simple: Incoming ICMP_1 hadi@noma1$ sudo tc/tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 match 00010000/00ff0000 at 8 action order 1: Simple <Incoming ICMP> index 4 ref 1 bind 1 installed 206 sec used 67 sec Action statistics: Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 SEE ALSO
tc(8) tc-actions(8) iproute2 12 Jan 2015 Simple action in tc(8)
All times are GMT -4. The time now is 03:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy