challenge 条件を満たす行を取り除く

ファイルから1行ずつ読み込み、"#"で始まる行だけを取り除いてファイルに出力するコードを書いてください。

サンプル入力

hello!
# remove this
 # don't remove this
bye!
サンプル出力
hello!
 # don't remove this
bye!

Posted feedbacks - R

1
2
3
4
5
remove.comment <- function(infile, outfile){
    sink(outfile)
    cat(grep("^[^#]", scan(file=infile, what=character(0), sep="\n"), value=TRUE), sep="\n")
    sink()
}

Index

Feed

Other

Link

Pathtraq

loading...