Archived from groups: microsoft.public.windowsxp.general (
More info?)
Ah! - so (some of) the files involved may not have a terminal newline.
FINDSTR appears to reproduce exactly what it found in the file, where the
file is a series of records terminated by NEWLINE or (naturally) the
physical end-of-file; prefixed by filename: if it's dealing with multiple
files. Consequently, it appends filename2:file2line to filename1:file1line
without a newline if it's missing from filename1.
Try:
....
echo\>dummy.txt
findstr "whatever" file1.txt dummy.txt>temp1.txt
findstr "whatever" file2.txt dummy.txt>temp2.txt
copy t1.txt+dummy.txt+t2.txt+dummy.txt resultfile.txt /b
....and if blank lines are a problem,
for /f "delims=" %%i in (resultfile.txt) do echo %%i>newresult.txt
HTH
....Bill
"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:e2hP%23bqtFHA.3752@TK2MSFTNGP09.phx.gbl...
> Now things are becoming clearer! All I can say is that
> this is the way findstr.exe appears to be designed. If you're
> interested in an in-depth discussion then I recommend that
> you repost this item in alt.msdos.batch.nt. There are a few
> players in there who will toss this one around until there
> is no meat left on the bone (and probably not much of the
> bone either!).
>
>
> "cliff" <cliff@discussions.microsoft.com> wrote in message
> news
B9D2619-EFF1-4276-9054-07C7062D38DE@microsoft.com...
>> hello,
>>
>> The last line should not have a newline for file1. When you used echo to
>> create file1, the last line has a newline.
>>
>> Instead of using echo to create file1, try using notepad and make sure
>> the
>> last line does not have a newline. I also noticed that "edit" also seems
> to
>> insert a newline for the last line(but not notepad).
>>
>> I also tested grep(a sort of findstr equivalent) and it does not have a
> this
>> problem when given the same file1 and file2.
>>
>> regards,
>> Cliff
>>
>> "Pegasus (MVP)" wrote:
>>
>> >
>> > "cliff" <cliff@discussions.microsoft.com> wrote in message
>> > news:C06F945C-B064-44E5-89FA-1E5E15370D4F@microsoft.com...
>> > > findstr output has a problem when the search word happens to be on a
> last
>> > > line of the preceding file. The output will be garbled with the
> succeeding
>> > > file searched.
>> > > e.g here shows a sample command line session showing the problem:
>> > > >> type file1
>> > > test
>> > > findstr
>> > > >> type file2
>> > > findstr
>> > > test
>> > > >> findstr "findstr" file1 file2
>> > > file1:findstrfile2:findstr
>> > >
>> > >
>> > > The desired output is one output per line like(this makes is easier
>> > > to
> do
>> > > pipe operations) :
>> > > file1:findstr
>> > > file2:findst
>> > >
>> >
>> > It is not clear from your post how you were testing your claim.
>> > Below is a sample batch file that attempts to duplicate what
>> > you were doing:
>> >
>> > @echo off
>> > echo String1>file1
>> > echo String2>>file1
>> > echo String2>file2
>> > echo String1>>file2
>> > findstr "String2" file1 file2
>> >
>> > When I run this batch file under WinXP Professional then I get
>> > the following screen output, which is pretty much what I expected:
>> >
>> > C:\Temp>try
>> > file1:String2
>> > file2:String2
>> >
>> > What did you expect? What do you get when you run this batch file?
>> >
>> >
>> >
>
>