Text
使用 v 查找的文本到表格
我有如下文件
嘗試:
awk ' !($3 in T1) {SQ[++CNT] = $3 } {T1[$3] = T1[$3] DL[$3] $1 T2[$3] = T2[$3] DL[$3] $2 DL[$3] = "," } END {for (i=1; i<=CNT; i++) printf "%s\t%s\t%s\t", T1[SQ[i]], T2[SQ[i]], SQ[i] print _ } ' file 1,3 2,4 5s 5 6 16s 7 8 23s
awk
GNU使用換行符或空格作為欄位分隔符的替代大錘,-F'[\n ]'
這也需要RS=""
以避免任何\n
被視為記錄分隔符。awk -F'[\n ]' 'BEGIN{RS=""; OFS="\t"} {print substr(FILENAME,1,length(FILENAME)-4), $1","$4, $2","$5, $3, $7, $8, $9, $10, $11, $12} ' *.txt
輸出:
File1 1,3 2,4 5s 5 6 16s 7 8 23s