Perl Script : Split given month into weeks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Script : Split given month into weeks
# 1  
Old 02-22-2008
Perl Script : Split given month into weeks

I want to split a given month into weeks. For example if I give the date in dd/mm/yy format say 01/02/08 it should give output in the given format :
week1 : start date and end date.
week2 : ""
week3 : ""
week4 : ""
# 2  
Old 02-22-2008
Code:
#!/usr/bin/ksh
echo ${1:-`date "+%d/%m/%y"`} | awk -F'/' '{print $2" 20"$3}' | \
        cal | awk '(NR>2)&&/[0-9]/{printf("week %d : %2d and %2d\n",NR-2,$1,$NF)}'

Output:
Code:
$ mth2wk
week 1 :  1 and  2
week 2 :  3 and  9
week 3 : 10 and 16
week 4 : 17 and 23
week 5 : 24 and 29
$
$ mth2wk 01/02/08
week 1 :  1 and  2
week 2 :  3 and  9
week 3 : 10 and 16
week 4 : 17 and 23
week 5 : 24 and 29

HTH
# 3  
Old 02-22-2008
link removed might get you started

Last edited by Perderabo; 02-22-2008 at 09:24 PM.. Reason: Remove link
# 4  
Old 02-22-2008
Quote:
Originally Posted by Yogesh Sawant
might get you started
That is a link to a pirated copy of the material. I doubt this forum allows the inconsiderate posting or such links.
# 5  
Old 02-22-2008
Please don't post links to copyrighted material. Thanks.
# 6  
Old 02-22-2008
Quote:
Originally Posted by khushbu_roy
I want to split a given month into weeks. For example if I give the date in dd/mm/yy format say 01/02/08 it should give output in the given format :
week1 : start date and end date.
week2 : ""
week3 : ""
week4 : ""
There are a number of Date modules on CPAN, Date::Range, Date::Simple, and a number of others that probably already do what you are asking.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies

2. UNIX for Beginners Questions & Answers

File Size Split up based on Month

Hi, I have a directory in Unix and there are folders available in the directory. Files are created on different month and now i have a requirement to calculate size of the folder on month basis. Is there any Unix command to check this please?? Thanks (6 Replies)
Discussion started by: Nivas
6 Replies

3. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

4. Shell Programming and Scripting

perl : searching for month and storing the date and time in an array

I am writing the code in perl. I have an array in perl and each variable in the array contains the data in the below format Now I need to check the below variable w.r.t system month I need to store the date and time(Tue Aug 7 03:54:12 2012) from the below data into file if contains only 'Aug'... (5 Replies)
Discussion started by: giridhar276
5 Replies

5. Shell Programming and Scripting

perl script to split the text file after every 4th field

I had a text file(comma seperated values) which contains as below 196237,ram,25-May-06,ram.kiran@xyz.com,204183,Pavan,4-Jun-07,Pavan.Desai@xyz.com,237107,ram Chandra,15-Mar-10,ram.krishna@xyz.com ... (3 Replies)
Discussion started by: giridhar276
3 Replies

6. Shell Programming and Scripting

perl script to split the filename

In PERL script I have few files named theme1.htm,theme2.htm,theme3.htm and so on. now I need to write perl code to split the the filename and store only that particular digit. Example -------------- filename is theme1.htm output should be 1 another example ---------------... (5 Replies)
Discussion started by: giridhar276
5 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. Shell Programming and Scripting

Perl script error to split huge data one by one.

Below is my perl script: #!/usr/bin/perl open(FILE,"$ARGV") or die "$!"; @DATA = <FILE>; close FILE; $join = join("",@DATA); @array = split( ">",$join); for($i=0;$i<=scalar(@array);$i++){ system ("/home/bin/./program_name_count_length MULTI_sequence_DATA_FILE -d... (5 Replies)
Discussion started by: patrick87
5 Replies

9. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

10. Shell Programming and Scripting

Isolating the Month in Perl

munt=`date '+%m` will isolate the month in digit form 02 = Feb Trying to get the same out of perl just cant see it $stimx = localtime($^T); print ((split/ /,$stimx)); (4 Replies)
Discussion started by: popeye
4 Replies
Login or Register to Ask a Question