Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tail command in bat file

1,070 views
Skip to first unread message

oracl...@lycos.com

unread,
May 5, 2005, 11:21:32 AM5/5/05
to
Hi all,

I am back again !!!

>From my earlier post I downloaded the UNIX compatible dos commands from
the suggested web site.

What I want to do is print last 40 lines of a large file on windows
2003 server.

I have tried the tail command in the command window as follows and it
works fine.

tail -40 c:\test\x.x > c:\test\a.a | start notepad /p c:\test\a.a

But when I use it in a batch file sometimes it works and sometimes it
does not. After playing with it a little bit in the bat file I came up
with the following:

cmd.exe /c tail -40 < c:\test\x.x > c:\test\a.a | start notepad /p
c:\test\a.a

When I change -40 to -60 or -10, I still get the same printout. Seems
like once created, it does not overwrite the c:\test\a.a. Also,
sometimes it does not print at all.

What am I doing wrong ? Can you please correct me.

Thanks.


Suresh

oracl...@lycos.com

unread,
May 5, 2005, 11:36:25 AM5/5/05
to
Hi all,

I am sorry. I found the problem.

There was a typo in my bat file there was a space between - and the
number of lines.
- 40 rather than -40.

The problem has been resolved.

Thanks.

Suresh

Ted Davis

unread,
May 5, 2005, 11:42:43 AM5/5/05
to

For one thing, that command should be something like this if you are
using the same TAIL I am:

tail -n 40 -s c:\test\x.x > c:\test\a.a && notepad /p c:\test\a.a

There is no apparent need to spawn a secondary command processor; it
is ambiguous whether the pipe should be triggered by CMD or by TAIL -
it is also uncertain when notepad would actually be launched relative
to the file write; and I see no reason to use START. Using the above
syntax will remove the ambiguities and force Notepad to start after
TAIL terminates. It would be best to use separate lines for the two
commands, but the above, except for printing (my printer is broken),
works correctly.

--
T.E.D. (tda...@gearbox.maem.umr.edu)

oracl...@lycos.com

unread,
May 5, 2005, 3:36:35 PM5/5/05
to
Ted,

Thanks for the reply.

You may have guessed that I intuitiveluy used my knowledge of UNIX to
do what I needed to do in Windows and it worked but that may not be the
best or correct way to do it.

Being new to windows I am always willing to learn the correct way and
thanks for showing me.

I have implemented it in my bat file and on 2 lines the way you
suggested and it works fine.

The '&&' did not work. What does it do anyway ? Also what does the
switch -s for tail do ?

It seems like tail works if everything is on 1 line. I tried to use ^
for continuing the long line and it did not work and have no knowledge
of how to figure out why it did not work.

Thanks again.

Suresh

Ted Davis

unread,
May 5, 2005, 10:15:28 PM5/5/05
to
On 5 May 2005 12:36:35 -0700, oracl...@lycos.com wrote:

>Ted,
>
>Thanks for the reply.
>
>You may have guessed that I intuitiveluy used my knowledge of UNIX to
>do what I needed to do in Windows and it worked but that may not be the
>best or correct way to do it.
>
>Being new to windows I am always willing to learn the correct way and
>thanks for showing me.
>
>I have implemented it in my bat file and on 2 lines the way you
>suggested and it works fine.
>
>The '&&' did not work. What does it do anyway ? Also what does the
>switch -s for tail do ?

&& is an IF operator: if the first part of the line terminates with a
success indication, then the second part is executed. You may be
using a different version of TAIL - one that does not return 0 on
success. The one I use has no help or version function, but forcing
it to dump its help by generating a syntax error produces this:

----------
E:\MyFiles\>tail --help
Error: Usage: tail lists file and directory sizes
Syntax: tail -n num [-f] [-p] -s file
f: print lines as file is updated
n num: number of lines to print
p: print remainder of file beginning at line num
s file: source file
----------


>
>It seems like tail works if everything is on 1 line. I tried to use ^
>for continuing the long line and it did not work and have no knowledge
>of how to figure out why it did not work.

Line continuation is not reliable, but maximum line length is great
enough that it is seldom actually necessary.


--
T.E.D. (tda...@gearbox.maem.umr.edu)

daniel brower

unread,
May 6, 2005, 6:49:43 AM5/6/05
to
there are three solid gold rules in computin'
1. if you want a bigger hard drive, BUY a bigger hard drive.
(any one remember doublespace?)
2. if you want a faster cpu, BUY a faster cpu.
(overclocking my chip wont hurt it! ERROR REA....)
3. if you needs windows to do something, WHATEVER it takes
(unix, c++, script, batch, apple code, ....)

<oracl...@lycos.com> wrote in message
news:1115321795....@g14g2000cwa.googlegroups.com...

0 new messages