Help with seq (print a series of dates)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with seq (print a series of dates)
# 1  
Old 08-10-2010
Help with seq (print a series of dates)

Assuming one does not have such luxuries as bash, zsh, jot, rs, perl, etc. what is the most elegant way to print out a formatted date series like this:

Code:
01-01-2010
01-02-2010
01-03-2010
...
02-01-2010
02-02-2010
...

Can I accomplish this with just basic shell builtins and seq, or perhaps other "ubiquitous" UNIX software tools? Maybe this is a job for awk and an incremented array?
# 2  
Old 08-10-2010
pass the date as a parameter to your script. this will working for you the way you want it..

Code:
 
let hours=$1*24
newdate=`TZ=CST-$hours date +%d-%m-%Y`
echo "$newdate"


Last edited by dazdseg; 08-10-2010 at 09:22 AM.. Reason: not proper editing
# 3  
Old 08-10-2010
Hi.

The dash shell is the nearest I have to a no-frills sh:
Code:
#!/usr/bin/env dash

# @(#) s2	Demonstrate calendar with builtins.

# Infrastructure details, environment, commands for forum posts. 
# Uncomment export command to run script as external user.
# export PATH="/usr/local/bin:/usr/bin:/bin"
set +o nounset
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe ; pe "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
pe "(Versions displayed with local utility \"version\")"
c=$( ps | grep $$ | awk '{print $NF}' )
version >/dev/null 2>&1 && s=$(_eat $0 $1) || s=""
[ "$c" = "$s" ] && p="$s" || p="$c"
version >/dev/null 2>&1 && version "=o" $p /usr/bin/printf specimen
set -o nounset

pl " Results:"
year=2010
month=1
for days in 31 28 31 30 31 30 31 31 30 31 30 31
do
  day=1
  while [ $day -le $days ]
  do
    # echo $month-$day-2010
    # printf "%02d-%02d-%4d\n" $month $day $year
    /usr/bin/printf "%02d-%02d-%4d\n" $month $day $year
    day=`expr $day + 1`
  done
  month=`expr $month + 1`
done |
specimen 4:4:4

exit 0

producing:
Code:
% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
dash (policy) 0.5.4-12
/usr/bin/printf printf (GNU coreutils) 6.10
specimen (local) 1.17

-----
 Results:
Edges: 4:4:4 of 365 lines in file "-"
01-01-2010
01-02-2010
01-03-2010
01-04-2010
   ---
07-01-2010
07-02-2010
07-03-2010
07-04-2010
   ---
12-28-2010
12-29-2010
12-30-2010
12-31-2010

Try it with your sh ... cheers, drl
# 4  
Old 08-11-2010
Thanks guys. Problem solved.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Easy seq Question

Hi! I'm trying to do this: 1 - 2 - 3 - 4 - 5 - I'm using seq for this: seq 1 20 > filename.txt How do I get the "-"? I've tried -f per man but can't get anything to work. Also, is there an easier or better way than using sequence? Thanks! (6 Replies)
Discussion started by: TonyBe
6 Replies

2. UNIX for Dummies Questions & Answers

RNA-seq analysis

I am processing RNA-seq data files that have been aligned using RUM. One of the output files is a *.sam that includes: Unique alignments Non-unique alignments original read files I want to extract only the unique alignments by pulling out alignments that have "IH:i:1" (indicates this read... (2 Replies)
Discussion started by: genGirl23
2 Replies

3. Shell Programming and Scripting

How to show first 0 using seq or +1 count?

Greetings, Using linux based OS and KSH. I m trying to make a simple script to parse some logs to show a count per hour on a specific alarm starting from midnight to the current hour. So I format my "HOUR" variable to show the current time and so I can use it in the following bit of code.... (6 Replies)
Discussion started by: Sekullos
6 Replies

4. Shell Programming and Scripting

Using seq (Or alternative)

I usually just browse the forum/google for answers, however I've been stuck on a problem for a number of hours now and I've decided to join up and actually ask I've searched the forum ad naseum in an attempt to find answer to my query, however so far I have been unsuccessful. I'm no expert... (3 Replies)
Discussion started by: gtc
3 Replies

5. Shell Programming and Scripting

Using Seq As A Variable With Padded Digits

Hi all. Im trying to use a sequence in a while loop like this below. I need it for navigating a year, month, day folder structure where a user can input the start date and have it go to the desired end date. The script will grab a certain file on each day then move onto the next. Ive got all that... (3 Replies)
Discussion started by: Grizzly
3 Replies

6. UNIX for Dummies Questions & Answers

print all dates 100 days from current date

can anyone please suggest me on ideas to write a script which has to go back to 100 days from 'current date' and print the date of each day starting from 100th day to current day. (korn shell please) Thanks Pavan (5 Replies)
Discussion started by: pavan_test
5 Replies

7. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

8. Shell Programming and Scripting

declaring variable with for $(seq)

Hi guys. i have the following script: 1 #!/bin/bash 2 linkcount=$(grep "/portal" tickets | wc -l) 3 grep "/portal" tickets > links 4 for i in $(seq 1 $linkcount); do 5 echo "BLYAT" 6 let link$i=$(sed -n "$i"p links) 7 echo $ 8 done the problem is, that "let" can`t... (1 Reply)
Discussion started by: neverhood
1 Replies

9. Shell Programming and Scripting

print 10 characters in series

suppose fileA kanika123ABC 1222222222222222 raciat5678ty 1221123333331121 jessica78ulllo 2233243223333333 so output shud be print only first 10 characters in series and rest remain same kanika123A 1222222222222222 raciat5678 1221123333331121 jessica78u ... (1 Reply)
Discussion started by: cdfd123
1 Replies

10. Shell Programming and Scripting

Compare dates in a field and print the latest date row

Hi, I need a shell script which should find the latest date in the field of file and print that line only. For eg., I have a file /date.log Name Date Status IBM 06/06/07 close DELL 07/27/07 open DELL 06/07/07 open : : : From... (1 Reply)
Discussion started by: cvkishore
1 Replies
Login or Register to Ask a Question