文件1:
1
2
Run Code Online (Sandbox Code Playgroud)
文件2:
1 2 3
4 5
Run Code Online (Sandbox Code Playgroud)
文件3:
x x x
yy yy
zz
Run Code Online (Sandbox Code Playgroud)
paste file1 file2 file2 给我一个标签分隔输出:
1 1 2 3 x x x
2 4 5 yy yy
zz
Run Code Online (Sandbox Code Playgroud)
paste -d" " file1 file2 file3 给我输出:
1 1 2 3 x x x
2 4 5 yy yy
zz
Run Code Online (Sandbox Code Playgroud)
我想要它如下:
1 1 2 3 x x x
2 4 5 yy yy
zz
Run Code Online (Sandbox Code Playgroud)
如果这是可能的,或者我应该尝试任何其他命令吗?
小智 7
可以使用sed删除标签
paste file file2 file3 | sed 's/\t/ /'
1 1 2 3 x x x
2 4 5 yy yy
zz
Run Code Online (Sandbox Code Playgroud)
这是一个通用的awk脚本,可以处理任何格式的任意数量的文件.
awk '
{x=ARGIND;a[x]=a[x]>(b=length($0))?a[x]:b}
{F[FNR,x]=$0}
END{
for(q=1;q<=FNR;q++)
{
for(i=1;i<=ARGC;i++)
{
printf( "%-"a[i]"s ",F[q,i])
}print ""
}
}' file{1,2,3,4)
Run Code Online (Sandbox Code Playgroud)