Need some help in formatting answer of shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need some help in formatting answer of shell script
# 1  
Old 07-16-2014
Debian Need some help in formatting answer of shell script

Dear all,
I am new to shell scripting and have tried to make a small program for fun sake that tells age from the last number of cell phone and birth year.
At the end we get a final 3 digit number and the first digit represents the last digit of cell phone and rest 2 numbers shows age. eg. 423 ---> 4 being the last digit of the cell number and 23 is the age.
Now i want to format the answer in such a manner that i can filter out the first digit and only display the last two digits as age.
The following is the script:
Code:
#!/bin/bash
echo "enter the last digit of your mobile number: "
read num
echo "Enter your birth year in YYYY format: "
read byear
mult=`expr $num \* 2`
fift=`expr $mult + 5`
fifty=`expr $fift \* 50`
plus=`expr $fifty + 1763`
agex=`expr $plus - $byear`
echo "$agex ------>>>> the first digit of the answer is your last digit of your cell number and last two digits represents your age"

I would request forum members to help me on this... i have enjoyed this and want to explore more.
Thanks in advance.
stg44

Last edited by Franklin52; 07-16-2014 at 04:19 PM.. Reason: Please use code tags
# 2  
Old 07-16-2014
Please use code tags as required by forum rules!

Using bash, did you consider the "parameter substring expansion" (man bash)?
# 3  
Old 07-17-2014
Ok. will use code tags next time. will keep in mind.
as for the "parameter substring expansion" i am totally new to this so please bear my silliness.
i did the man bash but unable to get how to relate and manipulate.
# 4  
Old 07-17-2014
${var:pos:len} will get you len characters of var, starting from pos. So
Code:
echo "${agex:1:2}"

https://www.gnu.org/software/bash/ma...Expansion.html
# 5  
Old 07-18-2014
Thanks a lot Carlo M.
I appreciate that, and will go through the bash reference manual.
SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting a file using shell script

Hi, Please find the below lines of a file B1/OT "GIB10" 837 130308 1351 MONORONOUS DIGI PATH FAULT SUPER B1/OT "GIB10" 520 130418 1537 MONORONOUS DIGI PATH FAULT SUPER B1/XT "GIB10" 762 130421 0653 TV Y-CEIVER ADMIN RXOCF-62 241_OKEBOLE_NEW 1 B1/XT "GIB10" 385 130425 1931 TV Y-CEIVER... (2 Replies)
Discussion started by: Ardhendu
2 Replies

2. Shell Programming and Scripting

Formatting File Using Shell Script

Hi Team, We have a requirement where we need to format input file using shell script by meeting the below conditions. 1. 1. Ignore first 549 characters of that file. 2. 2. After that we need to make a file of 100 characters per line, repeat it until the 3rd ... (16 Replies)
Discussion started by: ataneja7
16 Replies

3. Shell Programming and Scripting

formatting a shell script

there is one shell which calls for different sql scripts. output of different are formatted in frame like structure.i want columnar wise formatting to be done in such a manner that output of one sql may be comon input of rest sqls . ERC DML Closure Date ER DML SAP Transfer Date ... (0 Replies)
Discussion started by: arc
0 Replies

4. Shell Programming and Scripting

Help with shell script in formatting the records.

I have a text file in the following format. can any one please help me in printing the output in userfriendly format mentioned below. Input. 1) /ss/abc/1/w/s/domainname/abc1/logname/ ########error################### ########error################### ########error###################... (2 Replies)
Discussion started by: vinny81
2 Replies

5. Shell Programming and Scripting

Answer Terminal Questions With Shell Script?

First off, I am using Mac OS X, with Apple Remote Desktop. I have to install several app's on teachers' laptops which are on several cd's that I have made disk images of. (DMG's) To do rollouts quicker, I have written a script to mount the disk images and running the installers inside each of... (4 Replies)
Discussion started by: The Reepr
4 Replies

6. Shell Programming and Scripting

shell script that adds two integers and display answer on screen

please help shell script that adds two intergers and display answer on screen (1 Reply)
Discussion started by: wanyac2
1 Replies

7. Shell Programming and Scripting

formatting a file using shell script

Hi I have to do the following.I have to format a file test.t The contents are # Header 1231 xyz asdf asdapsdcsd //string1 = "pqrs" //string1 = "abcd"; //info //string1 = "*pqrs"; //add string1 = "#123"; //sub //string1 = "#1234567890" data = check(string1) //string1 = "#1234567890"... (12 Replies)
Discussion started by: gopsman
12 Replies

8. Shell Programming and Scripting

Shell script answer prompts?

Hi, I'm writing a script that calls a function to generate a certificate. In generating this certificate, I'm asked a series of questions. I was wondering, is there a way to pre-program my script to answer these questions in the same way all the time. I saw something like EOF>> y EOF ... (4 Replies)
Discussion started by: eltinator
4 Replies

9. UNIX for Advanced & Expert Users

Date Formatting in Shell Script

Hi, Can anybody throw somelight on how to handle date in a shell script? I need to pass the date in this format 'yymmdd' and then pad it to a file. The way in which i've handled is given below, but the date is not getting passed rather the file is getting created with a null date. Any... (2 Replies)
Discussion started by: Isiva
2 Replies

10. Shell Programming and Scripting

Formatting lines in shell script

I have a file with the below lines 1521 1522 1523 1524 1525 1526 ... 174 lines all numbers like above. I want the above file to appear as below. 1521,1522,1523,1524..... All the numbers should be separated by comma. Pls tell me how to do this .... Thanks in advance. (8 Replies)
Discussion started by: dreams5617
8 Replies
Login or Register to Ask a Question