output result (period -1)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output result (period -1)
# 1  
Old 05-18-2007
output result (period -1)

hello,

I have the following basic script which input the period, but I would like to output is period -1.. how?

echo Please input period (yyyymm):
read PERIOD
OUTPUT=$PERIOD -1
echo " you request period -1 is $OUT"

input 200705
output 200704
input 200701
output 200612

The above script is not work.

Please advise.

Thx!
# 2  
Old 05-18-2007
Search this forum, this problem has been answered many times.

Read this thread Getting yesterday DATE

Read this FAQ Yesterdays Date/Date Arithmetic

Read this TIP Simple date and time calulation in BASH

Jean-Pierre.
# 3  
Old 05-18-2007
Try...
Code:
echo "200701"|awk '{y=substr($0,1,4);m=substr($0,5,2)-1;if(m==0){m=12;y--};printf "%04d%02d\n",y,m}'

# 4  
Old 05-18-2007
Quote:
Originally Posted by anbu23
Code:
echo "Please input period (yyyymm):"
read PERIOD
OUTPUT=`expr $PERIOD - 1`
echo " you request period -1 is $OUTPUT"

Thx! it work now.

what is the meaning of "expr"?
# 5  
Old 05-18-2007
Quote:
Originally Posted by happyv
Thx! it work now.

what is the meaning of "expr"?
expr is a command which evaluate expressions.
I didn't read your requirement properly. My solution wont work for all the situations. Try Ygor's solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

Output result with break line

Hello, I am coding a script to check mysql databases using bash script, I would like to check if the status of a table is not 'OK', will return the table name and do some more actions: check.log table1 OK table2 Some error here table3 ... (5 Replies)
Discussion started by: Abu Rayane
5 Replies

3. Shell Programming and Scripting

How to get result of sqlcmd output in variable?

Hi All, I am looking for a solution. I am executing below command in shell script: SQL= "select count(*) from dual" sqlcmd --login /oracle/baccess.xml --sql "$SQL". I can see the result while executing above shell script. but I want to store the value of query output irrespective the... (2 Replies)
Discussion started by: lokendrasb
2 Replies

4. Shell Programming and Scripting

Format data output result

Hi guys, need a guide to format desire output result here. Please guide me. Thanks in advance. 2012-08-30 00:01:56,554 DEBUG - Sending message<TTT232MM0N048YCI TTPC TTOF1A 289171092679389OOLU 1562340 TPM 641 KT$YES 20120830000156KK 12012301??????000011YGY> to... (7 Replies)
Discussion started by: ment0smintz
7 Replies

5. Shell Programming and Scripting

how to output the array result into a matrix

I have a file like this: ASSPASVFETQY,hTRBV12-4,hTRBJ2-5,2 ASSPASTGGDYGYT,hTRBV18,hTRBJ1-2,2 ASSPASGDGYT,hTRBV5-1,hTRBJ1-2,2 ASSPASFPEDTQY,hTRBV27,hTRBJ2-3,2 ASSPARVNYGYT,hTRBV5-1,hTRBJ1-2,2 ASSPARTSGGLNEQF,hTRBV6-4,hTRBJ2-1,2 ASSPARQSYNEQF,hTRBV11-1,hTRBJ2-1,2... (3 Replies)
Discussion started by: xshang
3 Replies

6. Shell Programming and Scripting

Write result to output file

Good morning everybody, Beeing an absolute newbie in shell scripting I would like to look for some help here. I would like to read an external text file and format the data and write it to an output file. What I was trying to do was to display the result (this worked). But now I... (1 Reply)
Discussion started by: bluejean1976
1 Replies

7. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

8. Shell Programming and Scripting

script to output curl result as html

hi, new to scripting and would like to know how can I have a script which will curl a few URLs and have the results such as the URLs being curled, dns lookup time, connection time, total time, etc save in a html format in a form of table with column and rows. thank you. (4 Replies)
Discussion started by: squidusr
4 Replies

9. HP-UX

awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print. .... | awk '{print $0}' I would like it to print the date right before $0, so something like (this doesn't work though) .... | awk '{print date $0}' (4 Replies)
Discussion started by: IMTheNachoMan
4 Replies

10. Shell Programming and Scripting

Need to Output result to a non-delimitted file

Hello I need to run an sql script and then the output result to be in non-delimitted file What is the execution command to obtain this. For eg: the following outputs the result to a space delimitted file db2batch -d ${EC_DB2_DBNAME} -f ${TMP_SCRIPT_NAME} -a ${CURR_DB_ID}/${CURR_DB_PWD} -r... (1 Reply)
Discussion started by: cosec
1 Replies
Login or Register to Ask a Question