ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

delete all the lines that do NOT start with a specific string in multiple files

<< < (2/4) > >>

Ehtyar:
Well, I now despise Windows for having such a totally sucky console, but I managed to get this working.

As an exercise for myself I compiled GNU grep myself. It required a couple of patched but all-in-all relatively simple. If you're not capable of this yourself, you can get an only slightly outdated binary from UnxUtils (I've included my build in the attached zip). Converting the shell script to batch was a huuuge pain in the ass because (again) the Windows console sucks, and doesn't honor piping symbols in a for loop in the same way it would as a standalone command (you have to enclose your command in parens prior to the >, < or | symbol). God help you trying to find that in Google (I ended up randomly guessing it). Finally, grep on Windows converts CRLF line endings to plain LF (for internal operational reasons), so we need the todos utility to convert them back again.

So here you are, give it a try and let me know how it goes.

Ehtyar.

[edit]
Er...should this not be moved to the coding snack new request forum?
[/edit]

[edit2]
If you have cygwin, you can do this under windows as well.
-housetier (March 14, 2009, 12:30 PM)
--- End quote ---
MSYS will manage it also, minus the enormity of Cygwin.
[/edit2]

bgd77:
I think that the only way to do it is how Ehtyar suggested. i'm no expert in Windows Command Prompt, but I do not think that it is powerful enough to make changes in files. If someone knows better, please correct me!

One alternative would be to install ActivePerl or Python and to write a small program to do this, if you think that all the trouble is worthwhile.

Ehtyar:
*sigh*, life would indeed be easier if Windows came with a posix-compatible shell or Strawberry Perl, but alas, here I am passing around utilities that others would've had on almost any other operating system. I think, however, that this is a debate for another day.

kalos, would you let us know how it goes please?

Ehtyar.

rjbull:
Converting the shell script to batch was a huuuge pain in the ass because (again) the Windows console sucks, and doesn't honor piping symbols in a for loop in the same way it would as a standalone command
-Ehtyar (March 14, 2009, 05:44 PM)
--- End quote ---

Ehtyar,

Take a look at Horst Schaeffer's List MODifier LMOD, which is a great workaround for making batch files to get round these kind of problems.

Ehtyar:
I do like the sound of that utility rjbull, thanks for recommending it. However, the problem is no longer a problem, as I found the solution. I was complaining about the lack of documentation regarding the Windows console. Perhaps my searching skills failed me, but if you have to resort to guessing the syntax of any language, the documentation is in pretty poor shape.

Ehtyar.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version