If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to read parameter digits?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-02, 17:04
tcwang66 tcwang66 is offline
Registered User
 
Join Date: Feb 2002
Posts: 15
How to read parameter digits?

Hi,
I need to write a shell script to read a three digits value(including numbers and letters, such as K34 or 157....etc) from command parameter. How to deal with the parameter? Is it possible to convert the parameter string into characters and use Loop to get characters?
Any help will be appreciated.

Tien-Chih Wang
Reply With Quote
  #2 (permalink)  
Old 04-26-02, 18:37
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Can you submit an example of what you are trying to do ? What do you want to do with the 3 character strings ?
Reply With Quote
  #3 (permalink)  
Old 04-27-02, 23:14
tcwang66 tcwang66 is offline
Registered User
 
Join Date: Feb 2002
Posts: 15
I need to write a makefile shell script and the first pararmeter will be the release number. The release number must consist of three digit numbers(including either number or letter, such as 001, 002, or 3KH, A58). What I need to do is only to judge if the digits equals three and whether they belongs to either Number or Letters. That's it. It shouldn't be too difficult, but I still cannot find the way out.

Any help will be appreciated.

TC Wang
Reply With Quote
  #4 (permalink)  
Old 04-29-02, 05:25
geoffgomez geoffgomez is offline
Registered User
 
Join Date: Apr 2002
Posts: 17
You can check the number of letters in the variable using "wc -c":
(This will always return the number of characters +1, line ending character)

[oracle@oradb02 oracle]$ echo "K12" | wc -c
4
[oracle@oradb02 oracle]$ echo "K123" | wc -c
5


You can split the string to characters using "cut -c":

[oracle@oradb02 oracle]$ echo "K12" | cut -c1
K
[oracle@oradb02 oracle]$ echo "K12" | cut -c2
1
[oracle@oradb02 oracle]$ echo "K12" | cut -c3
2

You can test the characters as follows:

[oracle@oradb02 oracle]$ if echo "K12" | cut -c1 | grep [0-9] >/dev/null; then
> echo "NUMBER"
> elif echo "K12" | cut -c1 | grep [A-z] >/dev/null; then
> echo "LETTER"
> fi
NUMBER

Hope this is helpful,

Geoff
Reply With Quote
  #5 (permalink)  
Old 05-03-02, 10:51
tcwang66 tcwang66 is offline
Registered User
 
Join Date: Feb 2002
Posts: 15
Thanks. It really helps.

Tien-Chih Wang
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On