Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case scripting help

Status
Not open for further replies.
Dec 10, 2003
121
US
I have a file with the data similar to below:

stidm;Jul;15,;2003
franc;Aug;8,;2003
mracekd;Jul;15,;2003
adast;Sep;30,;2003

Many more records in this file but you get the point.

I need to convert the month to a numeric value and get this data into a file that looks like this:

stidm;07;15,;2003
franc;08;8,;2003
mracekd;07;15,;2003
adast;09;30,;2003

Would I use the Case command? If so, how do I pluck out part of the line, test against "Jul" (or whatever) and reinsert 07 (or corresponding value) back into another file with all the above information? (need data to look like adast;09;30,;2003 instead of adast;Sep;30,;2003)

The reason I am doing this is to delete users who have not logged into the system within the last 3 months. I'm pulling the current date and time as such: 11;2004
My plan was to compare against the year and month and send records older than 3 months or so to a file to be deleted. I did not want this to be static so I am trying to make it dynamic by pulling the current month and year and comparing my list of userids with last logins against it. [3eyes]
 
You could use cut and case for the transformation. I have something at work which might help - I'll post back when I get there! In the meantime, have you got anything you've tried?
 
Righto, this is the case statement I use (obviously it's the reverse of what you require, but you get the picture):
Code:
case $MONTH in
01)
export MONTH='Jan'
;;
02)
export MONTH='Feb'
;;
03)
export MONTH='Mar'
;;
04)
export MONTH='Apr'
;;
05)
export MONTH='May'
;;
06)
export MONTH='Jun'
;;
07)
export MONTH='Jul'
;;
08)
export MONTH='Aug'
;;
09)
export MONTH='Sep'
;;
10)
export MONTH='Oct'
;;
11)
export MONTH='Nov'
;;
12)
export MONTH='Dec'
;;
esac
You can assign $MONTH using cut -f2 -d ';' from your data above. There's probably a better way and if there is I'd be interested in seeing it. Cheers.
 
I did get this to work after reading some more. Here is what I used [thumbsup2]
cat logindate | while read y
do
month=`echo $y|awk -F\; '{print $2}'`
case $month in
Jan) echo $y|sed -e 's/Jan//'|awk -F\; '{printf("%s;01;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Feb) echo $y|sed -e 's/Feb//'|awk -F\; '{printf("%s;02;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Mar) echo $y|sed -e 's/Mar//'|awk -F\; '{printf("%s;03;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Apr) echo $y|sed -e 's/Apr//'|awk -F\; '{printf("%s;04;%s;%s\n",$1,$3,$4)}'>>monthnum;;
May) echo $y|sed -e 's/May//'|awk -F\; '{printf("%s;05;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Jun) echo $y|sed -e 's/Jun//'|awk -F\; '{printf("%s;06;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Jul) echo $y|sed -e 's/Jul//'|awk -F\; '{printf("%s;07;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Aug) echo $y|sed -e 's/Aug//'|awk -F\; '{printf("%s;08;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Sep) echo $y|sed -e 's/Sep//'|awk -F\; '{printf("%s;09;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Oct) echo $y|sed -e 's/Oct//'|awk -F\; '{printf("%s;10;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Nov) echo $y|sed -e 's/Nov//'|awk -F\; '{printf("%s;11;%s;%s\n",$1,$3,$4)}'>>monthnum;;
Dec) echo $y|sed -e 's/Dec//'|awk -F\; '{printf("%s;12;%s;%s\n",$1,$3,$4)}'>>monthnum;;
esac
 
Thanks for all the replies. This site is AWESOME because everyone helps make it that way with all their help!!! [thumbsup2] [peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top