Re: findstr output is garbled when the preceding files has no newline for the last line

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I can confirm the behavior and would too consider it a bug. The
following syntax (when executed from within a script) will create
similar output to the native findstr command if that's what you really
need -

for %%l in (f1 f2) do @set /p =%%l:<nul&findstr "findstr" %%l&echo/

.... it is, however, less efficient on large numbers of files that
findstr alone. If this is not precisely what you're after, please post
back with an expanded definition of your goal.

Note, the FIND.EXE command does not exhibit this behavior but uses a
different output format.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

cliff wrote:
> hello,
>
> 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 with
> file1.txt and file2.txt :
>
> c:\ > type file1.txt
> test
> findstr
> c:\ > type file2.txt
> test
> findstr
> c:\ > findstr "findstr" file1.txt file2.txt
> file1.txt:findstrfile2.txt:findstr
>
>
> The desired output is :
> file1.txt:findstr
> file2.txt:findstr
>
>
> The last line should not have a newline for file1.txt. 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.txt and file2.txt.
>
> Will this problem be fixed? It could cause some subtle problems in
> scripts when pipes are used.
> This problem exists on Windows 2000 and Windows XP.
>
> regards,
> Cliff


.



Relevant Pages

  • Re: Sed one liner (!?) for joining lines
    ... The ':a' creates a label, that your script can branch to. ... See the manual for the 't' command. ... # Change the newline, followed by an equals sign, to a space ... massive novel as a single paragraph, ...
    (comp.unix.shell)
  • Re: How may I override the LC_MESSAGES variable during login (JDS)
    ... Trond Norbye writes: ... >> Do you want to make it system wide a would propose adding a script in ... Do you have a newline after the setting of LC_MESSAGES? ... That command will not be executed then... ...
    (comp.unix.solaris)
  • Re: [opensuse] cron and every second saturday
    ... Ben Kevan wrote: ... The call of the script will still ... The ``sixth'' field specifies the command to be ... The entire command portion of the line, up to a newline or % ...
    (SuSE)
  • Re: Deleting blank lines
    ... > newline is just the end of line character, it's not a blank line (if I ... I'm trying to help someone edit some files from the command line, ... He has been struggling with all kinds of commands to append email addresses ... Then he can use the script when necessary to append to the files. ...
    (comp.unix.shell)
  • Re: findstr output is garbled when the preceding files has no newline for the last line
    ... cliff wrote: ... > findstr so that it will be a better cmd environment. ... >> similar output to the native findstr command if that's what you ... >>> This problem exists on Windows 2000 and Windows XP. ...
    (microsoft.public.win2000.cmdprompt.admin)