• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Search for string in file, save another file and paste data tin new file

We have a directory in c:\data and it contains hundred of sub directories and we want a batch to do a search of a text inside a file the once found create a new file and copy the content there. Here is the procedure:

1.-Directory with c:\data and inside there hundred of sub directories.
2.-On each sub directory there is a file called res2.html
3.-The script ON ALL files res2html inside each one of the hundred sub directories we need to check for:
4.-Search for the string "flv=../../../activ/" and store in a variable called A.
5.-Then search in same res2.html files for this other string "/videos2_1/video2_1.flv" and we can call B.
6.-Then between A and B in the middle of the both files there is a word that word we can call variable C.
7.-After find C and have located A and B also, the script must create a .html file with the name of the contents of the variable C and ending in .html. For example if C variable has a content called "course234" (without quotes of course) the resulting file must has the name "course234.html".
8.-For last step inside the file created "course234.html" the content stored there must be A+C+B.
9.-Process all the res2.html files inside all sub directories inside c:\data no matter if there is a need to process 1-8 steps for hundred of sub directories i side c:\data.

   To clear the example we have according above we have in A="flv=../../../activ/" and B="/videos2_1/video2_1.flv" and suppose the variable C, the word in the middle between A and B found by the script is the fictitious name "course234" (all without quotes of course). Then the script must create a file like C name ending in html in other words the new file created in the same directory is "course234.html" and inside of that new file created the content must be A+C+B in other words the content inside "course234.html" is "flv=../../../activ/course234/videos2_1/video2_1.flv" and again and like always without quotes.
   We don't know if this could be made in a batch of command prompt or maybe a visual basic script. I hope someone could help with the script, one way or another the script must run from command prompt. Could be .bat or .vbs.
Thank you
0
coerrace
Asked:
coerrace
  • 6
  • 5
1 Solution
 
aikimarkCommented:
What have you tried, so far?
0
 
coerraceAuthor Commented:
Until now nothing for that we ask here. Bu we heard command prompt batch could work fine.
Thank you
0
 
aikimarkCommented:
I can get you started with the windows batch script.
cd c:\data
dir /s /b res2.html

Open in new window

You're down to step 4, which I don't entirely understand and lack the context of seeing a res2.html sample file content.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
coerraceAuthor Commented:
I've requested that this question be deleted for the following reason:

Not answered
0
 
aikimarkCommented:
@corrence

You should participate in the solution.  EE is not a free coding service.  The volunteer experts help you solve problems.  If you need professional programming work done, please look at the profiles of the top experts.  Some of them have enabled their Hire Me links.

Alternatively, click on the Request Attention link and ask for more expert participation in this question.

I am objecting to your deletion request.
0
 
coerraceAuthor Commented:
Any way to do then?
Thank you
0
 
aikimarkCommented:
Any way to do then?
Did you click on the Request Attention link?
What have you tried to do?
What are you capable of doing on your own?

You have written a very detailed list of actions, but it does not appear that you have tried to actually do any of these things or explore how any of these actions might be performed (manually or otherwise).  In fact, this could be a homework/coursework assignment.
0
 
coerraceAuthor Commented:
We are working on assemble a site by parts and some functions and these kind of routines we can apply for actions in case of not work we look another possibility and of course that tasks can vary in a different form no matter if a solution is placed or not. I enter here to ask help when is needed sometimes pass months and I don´t enter. Actually we are in the middle of hundred of things and some comments or orientation could help in the middle of the hurricane. In fact this area we couldn't´t see via script code but we made a patch with this amazing tool:

http://findandreplace.codeplex.com/

   The problem with that is that it depends on the exe.
   And what you meant about res2.html is just only that file is on each sub directory but some little information on that files change between other res2.html´s then is why is needed make a search and replace action by sections like I explain where find the parts are equal in res2.html´s files and not touch the different parts because we only need want to change the equal parts like you see in description.
0
 
aikimarkCommented:
1. will those strings always be in every res2.html file?
2. are those strings exactly as you typed them?
0
 
aikimarkCommented:
1. Starting at the top of the directory tree for the res2.html files, run the following command
dir /s/b res2.html > ListOfRes2.txt

Open in new window


2. Place the attached VBS file in the same folder as the ListOfRes2.txt file and run it.
Q-28493857.vbs
0
 
coerraceAuthor Commented:
Working perfect.
Thank you
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now