RE: Silly little regex question
>
> In a shell script:
>
> `eval date +%j`
>
> returns the so-called "Julian" date (a misnomer I believe, but there
> it is), the number of days into the present year, aka "yearday":
>
> $ echo `eval date +%j`
> 036
>
> I want a regex that will strip the leading zero _or_ zeros (if it's
> January) from the yearday, using the shell contructions:
>
> ${string#substring} # strip shortest occurence of substring from the
> front of string
> or
> ${string##substring} # strip longest occurence of substring from the
> front of string
>
If you do not insist on using shell constructions, you can use 'sed':
$ date +%j | sed 's/^0\+\(.*\)/\1/'
36
or inside a shell script you might use:
T=`date +%j | sed 's/^0\+\(.*\)/\1/'`
If you insist on using this shell construction, it will look like:
T=`date +%j`
U=${T##"0"}
echo $U
> where substring is a regex.
>
This sentence makes me think I misunderstood your question.
HTH anyway,
Dan
Reply to: