View Single Post
  #3   (View Single Post)  
Old 6th July 2011
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 192
Default

If your numbers change often, you could make it an alias in .kshrc (or whatever shell you're using) as:
Code:
alias ca="awk 'BEGIN{for(i=ARGV[1]; i<ARGV[2]; i++) print \"cal \"i\" 2011\"}'"
That char escaping is needed. And then call it, for example, as:
Code:
$ ca 5 12
Apart from using awk's ARGV array, there is also "-v" option on (POSIX) compliant awk's for passing of shell variables to awk:

Code:
$ cat <<eof>test.awk
> #!/usr/bin/awk -f
>
> BEGIN{
> for(i=a; i<=b; i++) print "cal "i" 2011"}
> eof

$ ./test.awk -va=8 -vb=12
cal 8 2011
cal 9 2011
cal 10 2011
cal 11 2011
cal 12 2011
Cheers
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD
Reply With Quote