open Str
val _ = let
fun change f = let
val l = input_line f
val re = regexp "\(^SECTION=\).*"
val s = if string_match re l 0
then (replace_first re "\1" l)^"123"
else l
in
s::(change f)
end
handle End_of_file => nil
fun write f (s::sl) = output_string f (s^"\n") ; write f sl
| write f nil = ()
val fin = open_in "a.txt"
val a = change fin
val fout = open_out "a.txt"
val b = write fout a
in
()
end
cat a.txt | sed 's/^SECTION=[0-9]*/SECTI
cat a.txt | sed 's/^SECTION=[0-9]*/SECTION=123/' > a1.txt
하면 될것 같은데요.
물론 테스트는 안해 봤습니다.
고작 블로킹 하나, 고작 25점 중에 1점, 고작 부활동
"만약 그 순간이 온다면 그때가 네가 배구에 빠지는 순간이야"
음... php!
<? $input = file('a.txt'); $output = array(); foreach($input as $cur_line) { if('SECTION' == substr($cur_line,0,6)){$cur_line = 'SECTION=123';} array_push($output,$cur_line); } fwrite('a.txt',implode('\n',$output); ?>물론 테스트는 안해 봤습니다.
하핫.. c빼고 다 올라올 것같은 느낌이.. 짖굳으셔라~
하핫.. c빼고 다 올라올 것같은 느낌이.. 짖굳으셔라~
ㅡ_ㅡ;
[quote="tinywolf"]하핫.. c빼고 다 올라올 것같은 느낌이
전례가 몇 번 있지요, 아마...? ㅡㅡ
노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5
[quote="fehead"]cat a.txt | sed 's/^SECT
전 더 짖궃습니다.
드디어 고대하던 C 버전!
#include <stdlib.h> int main() { return system("cat a.txt | sed 's/^SECTION=[0-9]*/SECTION=123/' > a1.txt"); }Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.
# cd school# cd report# vi a.txt
# cd school
# cd report
# vi a.txt
-----[꼬릿말 절취선 시작]-----
삽질전에 먼저 구글신께 기도하자.
-----[꼬릿말 절취선 끝]-----
[code:1]#!/usr/bin/perlmy %FETCH;
#!/usr/bin/perl my %FETCH; my %REPLACE = ('SECTION' => '123'); $^I = ".bak"; while(<>) { chomp; $FETCH{$`} = $REPLACE{$'} || $' if(/=/); print $`,"=",$FETCH{$`},"\n"; }[code:1]#!/usr/bin/perlmy %FETCH;
#!/usr/bin/perl my %FETCH; my %REPLACE = ('SECTION' => '123'); $^I = ".bak"; while(<>) { chomp; $FETCH{$`} = $REPLACE{$`} || $' if(/=/); print $`,"=",$FETCH{$`},"\n"; }실행은 perl this.file 데이터 파일[/code]
[code:1]#!/usr/bin/perl my %FETCH;
#!/usr/bin/perl my %FETCH; my %REPLACE = ('SECTION' => '123'); $^I = ".bak"; while(<>) { chomp; if(/=/) { $FETCH{$`} = $REPLACE{$`} || $' ; print $`,"=",$FETCH{$`},"\n"; next; } print $_,"\n"; }앗 실수
$`가 전역 변수라서
결과는
#
TYPE=2
SECTION=123
#
퇴근전 심심해서 뭐 할 거 없나 했는데. 잘됐네요.[/code]
[code:1]open Strval _ = let fun c
open Str val _ = let fun change f = let val l = input_line f val re = regexp "\(^SECTION=\).*" val s = if string_match re l 0 then (replace_first re "\1" l)^"123" else l in s::(change f) end handle End_of_file => nil fun write f (s::sl) = output_string f (s^"\n") ; write f sl | write f nil = () val fin = open_in "a.txt" val a = change fin val fout = open_out "a.txt" val b = write fout a in () endnML 버전입니다.
요새 요놈으로 숙제 중이라..
저도 C 는 아닙니다....그래도 한번[code:1]perl -p
저도 C 는 아닙니다....그래도 한번
perl -pi -e "s/SECTION=3/SECTION=123/g" a.txt꽤 지났네요....머쓱
박장대소!
박장대소!
댓글 달기