Deleting lines in multiple txt files - batch?

October 19, 2010 at 13:33:02
Specs: Windows 7
Hey guys,

I'm looking to automate a process which will be very time-consuming if I do it by hand. I found this site by googling the problem, and people here have provided solutions to similar issues, so hopefully someone can help me!

The problem:
I have a large number of text files, part of which has useful information, part does not. I'd like to either move the useful parts into new text files (not sure if that's possible with large numbers of files), or delete the useless part.

The useful part of each file, which is all on one line, has a certain character in it, which is not in the rest of the file. However, everything in the useless parts is likely to be in the useful part, and the useless part is on several lines, so simply deleting a line will not cut it there. Make sense? If not, the files are all laid out roughly like this:



So, the way I see it, the possibilities are:
1. Run a command to move any lines containing # to a new file (one output file for each input file, so the line from file1.txt would go to file1new.txt, file2.txt to file2new.txt etc)
2. Run a command to delete any lines which do not contain #
3. Run a command to delete any text below !

Judging by the responses I saw to similar queries, a batch file may be the best idea - can anyone advise on how to do this, through a batch file or any other method?

Many thanks in advance to anyone who can help.

See More: Deleting lines in multiple txt files - batch?

Report •

October 19, 2010 at 17:35:09
download gawk for windows then do this

C:\test> gawk.exe "/#/{print}" file

Use a for loop to iterate files. You can search the forum on how to use for loops to iterate files.

GNU win32 packages | Gawk

Report •
Related Solutions

Ask Question