Input handling and formatting input to shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Input handling and formatting input to shell
# 1  
Old 04-26-2012
Bug Input handling and formatting input to shell

i want to get input and depending on it create new commands for input to expect.
But problem is that after giving date or month as 01-09 it is interpretation as 1-9





Code:
echo -n "ENTER DATE "
read d1
echo -n "ENTER MONTH "
read m1
echo -n "ENTER YEAR"
read y1

o=1
i=1
d2=`expr $d1 + 1`
while [ $i -lt $d2 ]
do

d"$o"="ls nc*$i$m1$y1* | wc -l"
echo "$(d$o) \c" >> input_to_expect.txt  ########### done for testing purpose only###
i=`expr $i + 1`
o=`expr $o + 1`

done


the expectd output in input_to_expect.txt is

Code:
ls nc*010412* | wc -l    ls nc*020412* | wc -l   ###########and so on as per input####


the actual output required is
the value of d1,d2.......dn ( as per i/p) should be as fallows so that it can be forwarded to expect


Quote:
d1 = ls nc*010412* | wc -l
d2= ls nc*020412* | wc -l
.
.
.
.$dn= ls nc*$i$m1$y1* | wc -l
# 2  
Old 04-26-2012
Try the Shell typeset command to declare all the variables which need to have leading zeros (and that includes $i and $o in your script).

Code:
typeset -Z2 var
var=3
echo $var

03

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

2. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

3. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

4. Shell Programming and Scripting

Formatting and combining fields of the input file

Hi, I have a file of the following format: AV 103 AV 104 AV 105 AV 308 AV 517 BN 210 BN 211 BN 212 BN 218 and the desired output is : AV 103-105 3 AV 308 1 AV 517 1 BN 210-212 3 (5 Replies)
Discussion started by: rochitsharma
5 Replies

5. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

6. Shell Programming and Scripting

Formatting input data

Hello everybody, I have a file containing some statistics regarding CPU usage. The file has this syntax : Fri Jul 16 14:27:16 EEST 2010 Cpu(s): 15.2%us, 1.4%sy, 0.0%ni, 82.3%id, 0.1%wa, 0.0%hi, 0.9%si, 0.0%st Fri Jul 16 15:02:17 EEST 2010 Cpu(s): 15.3%us, 1.4%sy, 0.0%ni, 82.3%id, ... (9 Replies)
Discussion started by: spiriad
9 Replies

7. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

8. UNIX for Dummies Questions & Answers

Handling input from a ls in a script

I'm trying to write a script that will handle the input from the ls command in my script so I can then manipulate the data. For example, I want to capture the output of the ls command in my script and then do a differences between the filename received in to another directory. ls |... (1 Reply)
Discussion started by: spookyrtd99
1 Replies

9. UNIX and Linux Applications

handling maximum number characters in an input file

Hi, Can anyone help me? An input file has three lines. Each line should only be 2098 as number of characters however line 2 of the input file has more than the maximum number of characters, it exceeded up to 4098. What should I do so that could handle maximum number of characters? that it could... (1 Reply)
Discussion started by: chrysSty
1 Replies

10. Shell Programming and Scripting

Handling null input...

Ok, so when a user inputs nothing, simply pressing enter when prompted for a phone number, I get a "./addrbkfct.sh: test: argument expected" error message. I have the following function: addNumber(){ echo "Phone number: \c"; read number; echo $number; if ;... (2 Replies)
Discussion started by: DrRo183
2 Replies
Login or Register to Ask a Question