using sed to grab two characters?
I am new to sed, but it seems to me this may be able to do what I want. I need to be able to capture two integers from a variable. I have a variable holding a date and time in the form YYYYMMDDHHMMSS.
For example if I have a variable holding 20040419204537, and I want to grab the hour (20) and place it in a new variable. Also, if possible, I would like to be able to capture the first 8 characters and put them into a new variable (20040419) Thanks for any help you can give! |
I'm not any good with sed, but here's a couple of C programs to do it easily:
Code:
gethour.c Code:
getdate.c |
echo 20040419204537 |
while read a; do hr=`echo $a | cut -c9-10` dt=`echo $a | cut -c1-8` echo $hr $dt done |
Code:
d="20040419204537" |
Thank you all very much. Such a quick response and good examples. This is a great site!
|
All times are GMT -5. The time now is 10:54 PM. |