| |
|
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.
|
 |
|

02-01-05, 23:55
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
|
help me.. i'm a newbie one
|
|
hello everyone,
i'm totally a newbie in this unix shell script area. i've learnt the simple coding such as echo, ls, date, clear, mv, mkdir and soon. just a simple code. i have a program to finish up. hope everyone can help me. thanks.
i have 3 directory, X, Y, Z. the coding write in Y that calls the raw data in X and produce the output in Z.
in X, i have many files that must be input for everyday (1 file for 1 day)... examples: status_11-01-2005.txt , status_12-01-2005.txt and soon
in Y, the coding sit here, report.sh
in Z, the output should be here, final.sh
in status_11-01-2005.txt, the raw data something like this:
02-02-2005 0133 0 10
02-02-2005 0133 1 11
02-02-2005 0133 2 10
02-02-2005 0133 3 12
02-02-2005 0133 4 15
02-02-2005 0133 5 10
02-02-2005 0137 1 10
in final.sh, the output should be like this:
[0] [1] [2] [3] [4] [5]
02-02-2005 Central1: 10 11 10 12 15 10
02-02-2005 Southern: 10 0 0 0 0 0
02-02-2005 Unknown: 1 0 0 0 0 0
02-02-2005 Overall: 20 11 10 12 15 10
Note: Excluding Unknown numbers
02-02-2005 Activebase: 33
Note: Excluding Unknown numbers. Adding [1], [2], [3]
hope this info will help you. thanks again.
|
|

02-02-05, 00:14
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
what have you gottten so far?
how do 'Central1', 'Southern' etc get derived from the given data?
how do you derive the numbers for the report in final.sh?
This does sound like a homework......
You wouldn't expect us to do the work for you, would you?
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-02-05, 00:56
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
|
|
totally no... actually, i've already built some part of coding. there's something like this. but i don't know how to read the data by daily basis.
the central1 and southern is a fix data (constant). which is central1=0133, southern=0137.
the file status_11-01-2005.txt and so on are key-in entry data that must be input everyday. e.g: 11-01-2005 for status_11-01-2005.txt , 12-02-2005 for status_12-01-2005.txt and so on.
the data for final.sh get from the data that i key-in everyday at status_11-01-2005.txt and so on. it's a daily concept.
in status_11-01-2005.txt, column 1 represent date, column 2 represent central1 or southern, column 3 represent status (0-preactive, 1-active, 2-GP, 3-barred, 4-terminate, 5-expired), column 4 represent total. it's key-in data. Unknown is data besides 0133 or 0137.
so in final.sh, overall=add value [0] in central1 and southern, [1] in central1 and southern; and so on. the unknown=[1]+[2]+[3]
the others, just add.
#!/bin/sh
cd /usr/aethos/snss/datafiles/REPORTING2/X
today=`date +%d-%m-%Y`
echo
echo "Date is "%today
cent1=0133
south=1037
cen=cent1
sou=south
file=status_$today.txt
echo "============================================"
echo " [0] [1] [2] [3] [4] [5] "
while [ $(file) != 0]
do
echo $today $cen:
echo $today $sou:
done < "$(file)"
echo "============================================"
hope you'll help me. thanks.
|
|

02-02-05, 01:18
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
ok how about :
Code:
while read date region status status junk
do
# at these point your row/line is broken into 4 columns/variable:
# date , region , status , status
# the fifth column [if it exists gets eaten into variable 'junk' - just for precaution
echo "today->[${today} region->[${region} status->[${region}]"
# now you can do your sum/average/whatever given the column breakdown from above
done < "${file}"
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-02-05, 21:32
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
can you help me, how can i call the file in sequently? is that true this coding?
file="status_$today.txt"
while [ "${file}" != 0 ]
do
while read date region status total junk
do
...
done
done < "${file}"
|
|

02-02-05, 21:39
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
no!
Code:
file="status_$today.txt"
while read date region status total junk
do
...
done < "${file}"
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-02-05, 21:58
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
so how can i call many file in sequently? e.g: status_11-01-2005.txt, status_12-01-2005.txt and etc. the raw data in this file are quite same but still have a different in total.
|
|

02-02-05, 22:14
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
I thought you wanted to do your processing ONLY for the CURRENT date - as you've created a file FROM the current date:
Code:
today=`date +%d-%m-%Y`
.
.
.
file=status_$today.txt
while read date region status total junk
do
...
done < "${file}"
Now........ if you want to process ALL the files regardless [which is quite different from your original requirement] you can do:
Code:
for file in status_*.txt
do
while read date region status total junk
do
...
done < "${file}"
done;
I strongly suggest reading the 'man' pages of the shell you're using and trying a couple of simple scripts increasing in sofistication.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-02-05, 22:55
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
sorry for the cause... i just write the coding like this...
Code:
I="/usr/X"
for file in status_*.txt
do
while read date region status total junk
....
done < file
done;
the output is they list out all of the file in the current directory(dir Y) not the content of a file in X dir.
|
|

02-03-05, 07:45
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
Code:
X="/usr/X"
Y="/usr/Y"
for file in ${Y}/status_*.txt
do
while read date region status total junk
....
done < "${file}"
done;
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-03-05, 22:23
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
thanks, it's work but it's not enough for what i want.
actually;
1) how can i separate the region into 3 (central1=0133, southern=0137 and unknown=besides central1 and southern)?
2) how can i separate the status into 6 (0, 1, 2, 3, 4, 5) by adding the total based on region? e.g: if 1 file have many region, status n total, i.e.
Code:
04-02-2005 0133 0 10
04-02-2005 0133 1 11
04-02-2005 0133 2 12
04-02-2005 0133 3 19
04-02-2005 0133 4 20
04-02-2005 0133 5 11
04-02-2005 0133 0 12
04-02-2005 0137 0 14
04-02-2005 0137 1 10
04-02-2005 0137 2 13
04-02-2005 0134 0 1
they should be like this:
Code:
[0] [1] [2] [3] [4] [5]
04-02-2005 CENTRAL1: 22 11 12 19 20 11
04-02-2005 SOUTHERN: 14 10 13 0 0 0
04-02-2005 UNKNOWN: 1 0 0 0 0 0
04-02-2005 OVERALL: 36 21 25 19 20 11
Note: Overall is adding central1, southern and unknown
04-02-2005 ACTIVEBASE: 65
Note: Activebase is [1]+[2]+[3]
i already done the coding...check this.
Code:
#!/bin/sh
X="/usr/X"
Y="/usr/Y"
for file in ${Y}/status_*.txt
do
while read line junk
date=`echo $line | cut -f1 -d" "`
region=`echo $line | cut -f2 -d" "`
status=`echo $line | cut -f3 -d" "`
total=`echo $line | cut -f4 -d" "`
case $status in
0) ... ;;
1) ... ;;
2) ... ;;
3) ... ;;
4) ... ;;
5) ... ;;
if [ region=0133 ] then
echo $date CENTRAL1: ...
else [ region=0137 ]
echo $date SOUTHERN: ...
done < "${file}"
done;
help me solve this...
|
|

02-03-05, 22:35
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
I believe my "hint" of the implementation of the inner loop was quite different and didn't require the useless use of multiple cut-s:
Code:
while read date region status total junk
I truely think that you have a good start to implement the rest of your logic.
You approach with the 'case' is the right way to go - try it and read "man" pages.
When/if you do hit a snag trying - pls post specific questions.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-03-05, 22:54
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
ok, i'll try my best first... thanks for being here to help me.
|
|

02-04-05, 03:21
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 12
|
|
is that true if i want adding by itself?
Code:
val=`expr "${total}"\+`
|
|

02-04-05, 09:31
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
i=`expr ${i} + ${total}`
I'd be much better off if you were using ksh instead of Bourne - 'man ksh'.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|