format a read command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format a read command
# 1  
Old 03-31-2010
format a read command

I have a read command like this:

Code:
print "enter the time to recover to: \n"
print "please use the format dd-mon-rrrr hh24:mi:ss"

read -n $dbtime

How do I format/check the read command to force the desired date/time format I want?
# 2  
Old 03-31-2010
Code:
$ print
-bash: print: command not found
$

We need at least some idea what language or shell you're talking about.
# 3  
Old 03-31-2010
Korn Shell .
# 4  
Old 03-31-2010
Look printf, how to change date string to epoc and so on. Maybe more easier to ask date in yyyymmdd hhmm format and then make checking ?
If you have gnu date, then date -d is also usable.
# 5  
Old 03-31-2010
Your code as you have it doesn't work.

Code:
$ read -n $dbtime
ksh: read: -n: numeric nbyte argument expected
Usage: read [-Aprsv] [-d delim] [-u fd] [-t timeout] [-n nbyte] [-N nbyte]
            [var?prompt] [var ...]
$ read -n dbtime
ksh: read: -n: numeric nbyte argument expected
Usage: read [-Aprsv] [-d delim] [-u fd] [-t timeout] [-n nbyte] [-N nbyte]
            [var?prompt] [var ...]
$ read dbtime
asdf
$

I don't think you can force read to reject input based on patterns, you'll just need to verify it yourself and make a loop:

Code:
while true
do
        print "please use the format dd-mon-rrrr hh24:mi:ss"
        read dbtime
        print "$dbtime" | egrep -iq "[0-9][0-9]-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]" && break
        print "Incorrect format, please use the format dd-mon-rrrr hh24:mi:ss"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and replace in format

Hi Guys, I am having below content in a file which is tab dimited file.txt AUS AUS_UP NZ NZ_UP ENG ENG_AP I need to read the file content and replace it with below output format one to one replace try("AUS ").ss("AUS_UP") try("NZ ").ss("NZ_UP") try("ENG ").ss("ENG_AP") (3 Replies)
Discussion started by: rohit_shinez
3 Replies

2. Shell Programming and Scripting

File read format issue in UNIX

hi all. my loop is getting failed eventhoug it is 1=1 but it is failure message. any help plz Output expected : echo "sucesss" code out=`cat bit.txt` if ]; then echo "sucess" else echo "Failure" (2 Replies)
Discussion started by: arun888
2 Replies

3. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

4. Shell Programming and Scripting

awk - Read fixed format

Hi, I have several fixed format ascii files which I would like to reformat through Awk. The fixed format produces intermittent whitespace (Nastran input file). $ Grid points $------1-------2-------3-------4-------5-------6-------7-------8-------9-------0 GRID* 1... (6 Replies)
Discussion started by: Tim Gowing
6 Replies

5. Shell Programming and Scripting

Read from text file;format and print output

Hi Following is the assumed input... Symmetrix ID : 12345 Originator Port wwn : 123456789 User-generated Name : 123456789/123456789 Sym Dev Dir:P LUN ------ ----- ----------------------- ---- --- ---- ---- ---- ------- 1234 ... (4 Replies)
Discussion started by: maddy.san
4 Replies

6. Shell Programming and Scripting

Read format problem in ksh script

I have ksh script reading file like while read -r line do echo $line sleep 1 #process_file $line done<$file_nm I want to write this line to another file after some manuplation.Put $line giving me line after changing line format(space removed).Please help me how can i read line by... (3 Replies)
Discussion started by: Mandeep
3 Replies

7. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

8. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

9. UNIX for Dummies Questions & Answers

format output from while read line

I have an output that I get from while read, I want to display it as the following, please help. Original output from while read line loop: This is my client=1 client version=2.3.4 OS version=4.5 This is my client=2 client version=1.5.6 OS version=6.7 I want it to look like this with... (7 Replies)
Discussion started by: dala
7 Replies

10. UNIX for Dummies Questions & Answers

Format Command

The reason I cannot install the Software Companion CD is that I have a hardrive that is 10GB. On my root slice/partition there is allocated 900MB, on my /export/home slice I have 8GB for use (these values were set by default on install). The software companion tries to install 600MB into my /opt... (2 Replies)
Discussion started by: yestoprop69
2 Replies
Login or Register to Ask a Question