用 alexandria 和 split-sequence 又實現了一個……
(ql:quickload :alexandria)
(ql:quickload :split-sequence)
(defvar f1 (alexandria:read-file-into-string #p"D:/1.txt"))
(defvar f2 (alexandria:read-file-into-string #p"D:/2.txt"))
(loop for line1 in (split-sequence:split-sequence #\Newline f1)
for line2 in (split-sequence:split-sequence #\Newline f2)
do (format t "~a~a~%" line1 line2))
于 2013-4-28 13:48, Mike Manilone 写道:
不合題目要求,因爲 不是vim/sed/awk - -
Common Lisp 版:
(with-open-file (stream1 #p"D:/1.txt" :direction :input)
(with-open-file (stream2 #p"D:/2.txt" :direction :input)
(loop for line1 = (read-line stream1 nil)
for line2 = (read-line stream2 nil)
until (or (null line1) (null line2))
do (format t "~a~a~%" line1 line2))))
因爲要手動在每行上迭代,所以有點長。。
可以先全讀出來再在每行上循環應該比較簡單 :-D
于 2013-4-27 8:21, 牛博恩 写道:
> 有两个文本文件,1.txt 和2.txt
> 我想把2.txt的内容附加到1.txt的每一行后面
> 比如1.txt内容是
> 1
> 2
> 3
> 4
>
> 2.txt的内容和1.txt相同,最后希望得到的效果是
> 11
> 22
> 33
> 44
> ----------------------
> 求用vim或者sed,awk这样的工具的解决办法
> --
>
Fedora中文郵件列表:https://admin.fedoraproject.org/mailman/listinfo
> /chinese
--
Fedora中文郵件列表:https://admin.fedoraproject.org/mailman/listinfo
/chinese