Need a scripting help
am 12.10.2007 14:23:42 von mritunjays
Hi all
MY shell script is creating one file which contain many OS level
command.
I am then executing that script.
I want to know the time taken by each command.
For that purpose i want to add date command after each line in the
that file like:
....
OS Command 1
date
OS Command 2
date
....
Can someone tell me how to add date command after each line in that
file?
It would be of great help for me.
You can mail me: mritunjays@gmail.com
Thanks
Mritunjay Sharma
Re: Need a scripting help
am 12.10.2007 14:29:33 von Ed Morton
mritunjays@gmail.com wrote:
> Hi all
>
> MY shell script is creating one file which contain many OS level
> command.
> I am then executing that script.
> I want to know the time taken by each command.
> For that purpose i want to add date command after each line in the
> that file like:
>
> ...
> OS Command 1
> date
> OS Command 2
> date
> ...
>
> Can someone tell me how to add date command after each line in that
> file?
> It would be of great help for me.
>
> You can mail me: mritunjays@gmail.com
>
>
> Thanks
> Mritunjay Sharma
>
awk '{print $0"\ndate"}' file > tmp && mv tmp file
Ed.
Re: Need a scripting help
am 12.10.2007 14:38:17 von Loki Harfagr
On Fri, 12 Oct 2007 05:23:42 -0700, mritunjays@gmail.com wrote:
> Hi all
>
> MY shell script is creating one file which contain many OS level
> command.
> I am then executing that script.
> I want to know the time taken by each command. For that purpose i want
> to add date command after each line in the that file like:
>
> ...
> OS Command 1
> date
> OS Command 2
> date
> ...
>
> Can someone tell me how to add date command after each line in that
> file?
> It would be of great help for me.
Use the toolbox, if sample file is:
$ cat /tmp/_lines
one
two
three
many
then, with awk:
$ awk '{print ; print "date"}ate/' /tmp/_lines
one
date
two
date
three
date
many
date
last
date
or, with sed:
$ sed 's/$/\ndate/' /tmp/_lines
one
date
two
date
three
date
many
date
last
unprotected shell:
$ while read ll; do printf ${ll}"\ndate\n" ; done < /tmp/_lines
one
date
two
date
three
date
many
date
here's a possible protected version:
( IFS="" ; while read ll; do printf ${ll}"\ndate\n" ; done < /tmp/_lines )
Re: Need a scripting help
am 12.10.2007 14:40:00 von mritunjays
On Oct 12, 5:29 pm, Ed Morton wrote:
> mritunj...@gmail.com wrote:
> > Hi all
>
> > MY shell script is creating one file which contain many OS level
> > command.
> > I am then executing that script.
> > I want to know the time taken by each command.
> > For that purpose i want to add date command after each line in the
> > that file like:
>
> > ...
> > OS Command 1
> > date
> > OS Command 2
> > date
> > ...
>
> > Can someone tell me how to add date command after each line in that
> > file?
> > It would be of great help for me.
>
> > You can mail me: mritunj...@gmail.com
>
> > Thanks
> > Mritunjay Sharma
>
> awk '{print $0"\ndate"}' file > tmp && mv tmp file
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
Thanks alot!
It worked perfectly :)
Re: Need a scripting help
am 12.10.2007 14:40:30 von Loki Harfagr
On Fri, 12 Oct 2007 12:38:17 +0000, loki harfagr wrote:
> $ awk '{print ; print "date"}ate/' /tmp/_lines
of course the bizarre "}ate" was a glitch in my X cut and paste :-)
$ awk '{print ; print "date"}/' /tmp/_lines
Re: Need a scripting help
am 16.10.2007 09:33:44 von Stephane CHAZELAS
2007-10-12, 05:23(-07), mritunjays@gmail.com:
> Hi all
>
> MY shell script is creating one file which contain many OS level
> command.
> I am then executing that script.
> I want to know the time taken by each command.
> For that purpose i want to add date command after each line in the
> that file like:
>
> ...
> OS Command 1
> date
> OS Command 2
> date
> ...
>
> Can someone tell me how to add date command after each line in that
> file?
> It would be of great help for me.
[...]
sed 'a\
date'
Or, at the beginning of your script, add
trap date DEBUG
and change the interpreter to bash, zsh or ksh93.
--
Stéphane