1.

Solve : need batch file to create files and insert date from an input file...?

Answer» <html><body><p>Well, I thought I was better at this than I am and I've got a problem I need some help with. I thought this would be simple, but at least right now, apparently I'm brain dead... <br/><br/>Here's the problem... I have a file called import.txt, the file layout looks like this...<br/><br/>4323<br/>Name of <a href="https://interviewquestions.tuteehub.com/tag/company-245057" style="font-weight:bold;" target="_blank" title="Click to know more about COMPANY">COMPANY</a><br/>Light<br/>no<br/>no<br/>no<br/>no<br/>no<br/>no<br/><br/>4325<br/>Name of next company<br/>#N/A<br/>no<br/>no<br/>no<br/>no<br/>no<br/>no<br/><br/>Each record is exactly the same size, seperated by a <a href="https://interviewquestions.tuteehub.com/tag/space-239477" style="font-weight:bold;" target="_blank" title="Click to know more about SPACE">SPACE</a>. Here's what I would like the batch file to do...<br/><br/>read import.txt<br/>Create a file from the first line of each record, i.e., 4323.txt<br/>insert the next eight lines exactly as shown<br/>move the the next record and do it all again until all the records are seperate files.<br/><br/>Thanks in advance for any help, I really appreciate it!<br/>Gary<br/>download <a href="http://gnuwin32.sourceforge.net/packages/gawk.htm">gawk for <a href="https://interviewquestions.tuteehub.com/tag/windows-22662" style="font-weight:bold;" target="_blank" title="Click to know more about WINDOWS">WINDOWS</a></a>, then use this one liner<br/><br/> Code: <a>[Select]</a>C:\test&gt;gawk -vRS= -vFS="\n" "{print $<a href="https://interviewquestions.tuteehub.com/tag/0-242464" style="font-weight:bold;" target="_blank" title="Click to know more about 0">0</a> &gt; $1\".txt\"}" file<br/><br/>C:\test&gt;more 4325.txt<br/>4325<br/>Name of next company<br/>#N/A<br/>no<br/>no<br/>no<br/>no<br/>no<br/>no<br/><br/>C:\test&gt;more 4323.txt<br/>4323<br/>Name of Company<br/>Light<br/>no<br/>no<br/>no<br/>no<br/>no<br/>no<br/>I wanted to share the answer with anyone who might have been interested in this problem.  It came from a different forum I'm a member of, from a guy named aGerman.  Here's his reply...<br/><br/>-------------------------<br/><br/>It's not that easy. Maybe it will fail if the number of lines is greater than the 32bit <a href="https://interviewquestions.tuteehub.com/tag/limit-237994" style="font-weight:bold;" target="_blank" title="Click to know more about LIMIT">LIMIT</a> for numeric expressions in batch.<br/><br/><br/>Code:<br/>echo off &amp;setlocal<br/>set "empty=0"<br/>for /f "delims=: tokens=1*" %%a in ('findstr /n "^" "import.txt"') do (<br/>  if "%%b"=="" (<br/>    call set "empty=%%empty%% %%a"<br/>  ) else (<br/>    set "line_%%a=%%b"<br/>  )<br/>)<br/><br/>for %%a in (%empty%) do (<br/>  set /a nameLine=%%a+1<br/>  set /a startLine=%%a+2<br/>  set /a endLine=%%a+9<br/>  call :proc<br/>)<br/>goto :eof<br/><br/>:proc<br/>call set "name=%%line_%nameLine%%%.txt<br/>if "%name%"==".txt" goto :eof<br/>&gt;"%name%" type nul<br/>for /l %%a in (%startLine%,1,%endLine%) do (<br/>&gt;&gt;"%name%" call echo.%%line_%%a%%<br/>)<br/>goto :eof<br/><br/><br/><br/><br/>This code should work if the separator is an empty line.<br/>But you wrote the separator is a space. If this is realy true you have to replace:<br/><br/>Code:<br/>  if "%%b"==" " (<br/><br/>-----------------------------<br/><br/></p></body></html>


Discussion

No Comment Found