module Main where
import Text.ParserCombinators.Parsec
main = do
let delim = string "----\n" <|> do{eof; return ""}
let p = many (do{x <- anyChar; xs <- manyTill anyChar delim; return (x:xs)})
Right ss <- parseFromFile p "in.txt"
sequence (zipWith (\ i s -> writeFile ("out"++show i++".txt") s) [0..] ss)
ㅇ.,ㅇ 이거..
이거 설마 대학과재? ㅎㅎㅎ
--------------------------------------------------------------
허접한 페도라 가이드 http://oniichan.shii.org
---------------------------------------------------------------------------------------------------------------
루비 온 레일즈로 만들고 있는 홈페이지 입니다.
http://jihwankim.co.nr
여러 프로그램 소스들이 있습니다.
필요하신분은 받아가세요.
대충
대충 이런식이겠죠.
잘 돌아가는지는 모르겠습니다.
#!/usr/bin/perl use strict; use warnings; die usage() unless @ARGV >= 1; my $delim = shift; my %subfile = ( number => 0, prefix => 'delim-', postfix => '.txt', lines => [], ); LOOP_LINES: while ( my $line = <> ) { if ( $line !~ m/^$delim$/ ) { push @{$subfile{lines}}, $line; next LOOP_LINES; } save_to_file( "$subfile{prefix}$subfile{number}$subfile{postfix}", @{$subfile{lines}} ); $subfile{lines} = []; ++$subfile{number}; } if ( @{$subfile{lines}} ) { save_to_file( "$subfile{prefix}$subfile{number}$subfile{postfix}", @{$subfile{lines}} ); } sub save_to_file { my $file = shift; my @lines = @_; open my $fh, '>', $file or die "cannot open $file : $!\n"; print $fh @lines; close $fh; } sub usage { my $str = <<"END_USAGE"; USAGE ===== $0 <delimeter> <file> [<file> ...] END_USAGE return $str; }---------------------------
Smashing Watermelons~!!
Whatever Nevermind~!!
Keedi Kim
----
use perl;
Keedi Kim
Haskell 버전
Haskell 버전입니다.
module Main where import Text.ParserCombinators.Parsec main = do let delim = string "----\n" <|> do{eof; return ""} let p = many (do{x <- anyChar; xs <- manyTill anyChar delim; return (x:xs)}) Right ss <- parseFromFile p "in.txt" sequence (zipWith (\ i s -> writeFile ("out"++show i++".txt") s) [0..] ss)csplit
csplit을 사용하시면 될것 같네요.
댓글 달기