|
Home > Archive > Unix Shell > September 2006 > capturing the time stamp in desired format
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
capturing the time stamp in desired format
|
|
| pawan_test 2006-09-21, 7:29 pm |
| Hello All,
I am working on korn shell script.i have 2 questions;
1) I have a file and i am able to capture the arrival time.
the arrival time is capturing as 11:30
ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}'
11:30
my desired output is 113000
can anyone please suggest me how do i do this.
2) I have another question.
I have a timestamp as 20060921094743
my desired output is 094743
can anyone please suggest me how do I only display the last 6 digits
from the timestamp.
Thanks a bunch
pavi
| |
| Xicheng Jia 2006-09-21, 7:29 pm |
| pawan_test wrote:
> Hello All,
>
> I am working on korn shell script.i have 2 questions;
>
> 1) I have a file and i am able to capture the arrival time.
> the arrival time is capturing as 11:30
>
> ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}'
>
> 11:30
>
> my desired output is 113000
> can anyone please suggest me how do i do this.
change your awk line:
awk -F':| *' '{print $8 $9 "00"}'
or pipe to sed(GNU sed):
sed 's/://; s/$/00/'
If it's shell variable, you can(GNU bash):
var1='11:30'
var2="${var1/:/}00"
> 2) I have another question.
> I have a timestamp as 20060921094743
> my desired output is 094743
> can anyone please suggest me how do I only display the last 6 digits
> from the timestamp.
timestamp=20060921094743
printf "%s\n" "${timestamp#????????}"
printf "%s\n" "$timestamp" | cut -c9-
printf "%s\n" "$timestamp" | sed 's/.*\([0-9]\{6\}\)$/\1/'
Regards,
Xicheng
| |
| Chris F.A. Johnson 2006-09-22, 1:41 am |
| On 2006-09-21, pawan_test wrote:
> Hello All,
>
> I am working on korn shell script.i have 2 questions;
>
> 1) I have a file and i am able to capture the arrival time.
> the arrival time is capturing as 11:30
>
> ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}'
>
> 11:30
>
> my desired output is 113000
> can anyone please suggest me how do i do this.
set -f
set -- $(ls -ltr aaa.bbb.332121312.*.*)
time=$8
hour=${time%:*}
minute=${time#*:}
second=00
printf "%s\n" "$hour$minute$second"
> 2) I have another question.
> I have a timestamp as 20060921094743
> my desired output is 094743
> can anyone please suggest me how do I only display the last 6 digits
> from the timestamp.
timestamp=20060921094743
printf "%s\n" "${timestamp#"${timestamp%??????}"}"
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Barry Margolin 2006-09-22, 7:28 pm |
| In article <1158881678.916788.225120@k70g2000cwa.googlegroups.com>,
"pawan_test" <sridhara007@gmail.com> wrote:
> Hello All,
>
> I am working on korn shell script.i have 2 questions;
Please don't multi-post. You've already gotten answers in
comp.unix.programmer and comp.unix.questions.
If you REALLY think your posting is appropriate for multiple groups,
please cross-post a single thread, rather than posting the same question
multiple times.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|