- How to split a file in parts ?
- Posted by lisztnet@aliceadsl.fr on July 6th, 2008
Only tools allowed
AWK version 3, SED 1.5 or Qbasic or batch (all that work on Hp 200lx.
One assume that OP (me) has insert some string like @@@@ at the
suitable location for the split...i did some search, but couldn't find
a ready to use solution, most of it concerns Unix help or even perl.
thanks very much,
L
- Posted by lisztnet@aliceadsl.fr on July 6th, 2008
On 6 juil, 18:37, liszt...@aliceadsl.fr wrote:
Well i should be able to achieve it in basic..soon
L
- Posted by billious on July 6th, 2008
<lisztnet@aliceadsl.fr> wrote in message
news:5e07dc64-1024-4320-86cd-9ebaac2ed11c@e53g2000hsa.googlegroups.com...
This solution developed using XP
It may work for NT4/2K
----- batch begins -------
[1]@echo off
[2]del outfile*.txt 2>nul
[3]find /n "@@@@" <infile.txt>splits.txt
[4]set yfn=0
[5]call :newfile
[6]for /f "tokens=1*delims=[]" %%i in ( ' find /v /n "" ^<infile.txt ' ) do
(
[7]call
rocess %%i
[8]if defined ypl (>>outfile.txt echo\%%j) else (call :newfile)
[9])
[10]call :newfile
[11]del splits.txt 2>nul
[12]goto :eof
[13]
[14]
rocess
[15]set ypl=Y
[16]if [%yml%]==[%1] set ypl=
[17]goto :eof
[18]
[19]:newfile
[20]set yml=
[21]if exist outfile.txt ren outfile.txt outfile%yfn%.txt
[22]set /a yfn+=1
[23]for /f "tokens=1,2delims=[]" %%x in ( ' find /n /v "" ^<splits.txt' ) do
if %%x==%yfn% set yml=%%y
[24]goto :eof
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof
The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.
- Posted by Ted Davis on July 7th, 2008
On Sun, 06 Jul 2008 09:37:59 -0700, lisztnet wrote:
Reinventing the wheel - csplit does exactly that.
In awk - using output files names equal to the source, but with a
numerical prefix:
awk "BEGIN{C=1}{if($0~/@@@@/){C++}else{print $0 > C \"-\"
FILENAME}}" source_file
(one line) That omits the marker - if you want the marker, you have to
decide which file it goes in before anyone can code that.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
- Posted by lisztnet@aliceadsl.fr on July 7th, 2008
On 7 juil, 04:26, Ted Davis <tda...@umr.edu> wrote:
Yes lately i fund csplit, here :
http://short.stop.home.att.net/freesoft/unix.htm
and command line like that :
http://delfin.klte.hu/aixdocs/normal...ds1/csplit.htm
Examples
1. To split the text of book into a separate file for each chapter,
enter:
csplit book "/^ Chapter *[k.0-9]k./" {9}
This creates 10 files, xx00 through xx09. The xx00 file contains
the front matter that comes before the first chapter. Files xx01
through xx09 contain individual chapters. Each chapter begins with a
line that contains only the word Chapter and the chapter number.
2. To specify the prefix chap for the files created from book,
enter:
csplit -f chap book "/^ Chapter *[k.0-9]k./" {9}
This splits book into files named chap00 through chap09.
Regarding AWK :
d:\mes documents\hp200lx\awk320>awk "BEGIN{C=1}{if($0~/@@@@/){C+
+}else{print $0
^
awk ERROR: syntax error
There is maybe an error at \"-\"
my version of AWK removes the slashes and then give the error.
L
- Posted by Richard Bonner on July 7th, 2008
lisztnet@aliceadsl.fr wrote:
*** I don't have a specific solution but here are some avenues to
research:
1/ You could try a word processor's "Search & Replace" feature to
find that text and replace it with a page break.
2/ Use MiniTrue or SED to do the above by relacing that text with an
end-of-file (^Z) marker and then use that to generate separate files.
3/ If the parts are not too large, XSET might be able to be used to define
each section and save it to a file.
One or more links to the programs mentioned can be found at:
http://www.chebucto.ca/~ak621/DOS/Websites.html
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
- Posted by Ted Davis on July 7th, 2008
On Mon, 07 Jul 2008 03:06:54 -0700, lisztnet wrote:
A proper version of awk issues a message that \" has been treated as
plain ".
gawk is the standard version - the most used version, the one that comes
with pretty much all Linux and BSD distros, and the one assumed unless
something else in positively identified in discussions in comp.lang.awk.
That command line syntax is required under Windows and it was tested
(under XP).
Incidently, the program can be improved to allow more output files by
replacing "C++" with "close(C++) \"-\" FILENAME" - that prevents running
out of file handles.
--
T.E.D. (tdavis@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).