

InterviewSolution
Saved Bookmarks
1. |
Solve : Help with batch...? |
Answer» <html><body><p>hello, very nice community<br/><br/>i have made the following batch <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a><br/><br/> Code: <a>[Select]</a>ECHO off<br/>cls<br/>:start<br/>set /p input=Write What are you search for :<br/>findstr /n /i /c:%input% * /all > %input%_bY_Chrisad.txt<br/>goto end<br/>:end<br/><br/>What this do : <br/><br/>ask from user to insert a string<br/>Search all text files in the directory for some string that user want.<br/>Collect the lines of texts that contain the string<br/>and create a new text file named searched_string_by_Chrisad.txt<br/><br/>Works Gr8! <br/><br/>but i need to do some changes and i need help. <br/><br/>i want same procedure but i want the searched sting not entered by user but to be at a text file stings.txt like that :<br/><br/>sting1<br/>sting2<br/>sting3<br/><br/>.......<br/><br/>and search for the fist (sting1) all text files ---> and create as results sting1.txt <br/><br/>after <br/><br/>search for the second (sting2) all text files ---> and create as results string2.txt<br/><br/>after <br/><br/>search for the <a href="https://interviewquestions.tuteehub.com/tag/third-1414358" style="font-weight:bold;" target="_blank" title="Click to know more about THIRD">THIRD</a> (sting3) all text files ---> and create as results string3.txt<br/><br/>hope to be understandable <br/><br/>thanks for any help<br/>My batch is a bit rusty, but you can do this using FOR<br/><br/>ECHO off<br/>cls<br/>:start<br/>set /p input=Write What are you search for :<br/>findstr /n /i /c:%input% * /all > %input%_bY_Chrisad.txt<br/>goto end<br/>:end<br/><br/><strong>for /f "tokens=1*" %%a in ('type INPUTFILE.TXT') do findstr /n /i /c:%%a%%b * /all > %input%_bY_Chrisad.txt</strong>thanks for reply, <br/><br/>i try this : <br/><br/> Code: <a>[Select]</a><br/>ECHO off<br/>cls<br/>:start<br/>for /f "tokens=1*" %%a in ('type INPUTFILE.TXT') do findstr /n /i /c:%%a%%b * /all > results.txt<br/>goto end<br/>:end<br/><br/><br/>but :<br/><br/>if INPUTFILE.TXT have 5 lines <br/><br/>text1<br/>text2<br/>text3<br/>text4<br/>text5<br/><br/>i take the message :<br/><br/>findstr : CANNOT OPEN */ALL<br/>findstr : CANNOT OPEN */ALL<br/>findstr : CANNOT OPEN */ALL<br/>findstr : CANNOT OPEN */ALL<br/><br/>Four times and i take results only for the last line (text5) <br/><br/>the same thing <a href="https://interviewquestions.tuteehub.com/tag/happen-1015459" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPEN">HAPPEN</a> if the INPUTFILE.TXT have 2-3-5 or any other number of values only take the last one...<br/><br/>any other help ?I have 1 txt file X having <a href="https://interviewquestions.tuteehub.com/tag/fields-251233" style="font-weight:bold;" target="_blank" title="Click to know more about FIELDS">FIELDS</a> a, b, c and I want to make Y file which would only contain b field from X file with the help of batch file. Kindly help how I can make it? <strong>('type INPUTFILE.TXT')<br/></strong><br/><br/>I think the problem is you're not including the path..<br/><br/><strong>('type C:\folder\INPUTFILE.TXT')</strong><br/><br/>Or maybe change directory</p></body></html> | |