我有两个文件,行和列的数量相同。用;
分隔。例子;
file_a:
1;1;1;1;1
2;2;2;2;2
3;3;3;3;3
4;4;4;4;4
file_b:A;A;A;A;A
B;B;;;B
;;;;
D;D;D;D;D
忽略定界符,file_b
中的第3行为空。因此,我也想在命令之前从file_a
中删除第3行;paste -d ';' file_a file_b
。为了得到这样的输出:
1;1;1;1;1;A;A;A;A;A
2;2;2;2;2;B;B;;;B
4;4;4;4;4;D;D;D;D;D
编辑:列数是93,并且每行和两个文件的列数相同,因此两个文件的行和列矩阵完全相同。
最佳答案
您能否请尝试按照GNU awk
中显示的示例进行后续操作,编写和测试。
awk '
BEGIN{
FS=OFS=";"
}
FNR==NR{
arr[FNR]=$0
next
}
!/^;+$/{
print arr[FNR],$0
}
' file_a file_b
说明:添加以上详细说明。awk ' ##Starting awk program from here.
BEGIN{ ##Starting BEGIN section from here.
FS=OFS=";" ##Setting field separator and output field separator as ; here.
}
FNR==NR{ ##Checking condition if FNR==NR which will be TRUE when file_a is being read.
arr[FNR]=$0 ##Creating arr with index FNR and value is current line.
next ##next will skip all further statements from here.
}
!/^;+$/{ ##Checking condition if line NOT starting from ; till end then do following.
print arr[FNR],$0 ##Printing arr with index of FNR and current line.
}
' file_a file_b ##Mentioning Input_file names here.
关于awk - 从文件中删除与另一个文件的空白行相对应的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64041626/