Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Data From Text File

Status
Not open for further replies.

pmaths

MIS
Feb 15, 2007
37
GB
Hi,

I'm looking to create a batch file that will run the net file command on a PC to output a list of all of the open files and then from the created list search and extract the lines where a certain text string is present.

I would then want to extract all none required data from the serach results to leave only the ID No of the open files. I would then use the ID No again with the net file command to close the open files I want.

I'm hoping that someone can advise on what command I need to use to search on and extract the data I need but also maybe point me in an alternative direction to achieve what I'm looking to achieve if there is a better way.

The whole purpose of this is to give a none admin user permission to close certain open files on our server.

Many Thanks.
 
try using the find command and pipe the output to a file

ex: find "mystring" infile.txt > outfile.txt

Mike Butler
Now former Iseries Guy -> PC's back, SUNs gone Iseries gone- BooHoo
"Never put off 'til tomorrow what you should have done yesterday
 
Also, FINDSTR works quite well.

If you want to find any line that has "PICKME!", you'd key
[tt][blue] findstr "PICKME!" infile.txt > outfile.txt[/blue][/tt]

To ignore upper/lowercase comparisons, use the "/i" flag:
[tt][blue] findstr /i "pickme!" infile.txt > outfile.txt[/blue][/tt]

Typing [tt]findstr /?[/tt] will give you more info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top