awk基本就是C的String处理了.语法都一样
awk '
NR == FNR { s[NR]=$0; nMax=NR; }
NR > FNR { s[FNR]=s[FNR]$0; }
END { i=1;
while (i<=nMax) {
print s[i]; i++;
}
}
' file1 file2
这是一第一个文件长度为准的版本,很经典的C语法.
On 10:00 Sat 27 Apr , Zhenbo Li wrote:
> 第一反映是用C++写。。。
> 用string库也没几行
>
>
> 在 2013年4月27日上午9:52,Úcarenya <infernoxu(a)gmail.xn--com>:-0s6m5392c
>
> > awk 'NR == FNR {s[NR]=$0} NR > FNR {print s[FNR]$0}'
> >
> >
> > On 08:21 Sat 27 Apr , 牛博恩 wrote:
> > > 有两个文本文件,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
> >
> > --
> > - Úcarenya - infernoxu at gmail dot com
> > -
http://ucarenya.com/
> > --
> >
Fedora中文郵件列表:https://admin.fedoraproject.org/mailman/listinfo/chinese
> >
>
>
>
> --
> Have a nice day!
> Zhenbo Li
> --
>
Fedora中文郵件列表:https://admin.fedoraproject.org/mailman/listinfo/chinese
--
- Úcarenya - infernoxu at gmail dot com
-
http://ucarenya.com/
--
Fedora中文郵件列表:https://admin.fedoraproject.org/mailman/listinfo/chinese