0
單詞中的文件結合我有文件1無法被Zsh/AWK
A,B,C
和File2
D,E,F
我試圖通過
echo {`cat File1`}{`cat File2`}
有
AD, AE, AF, BD, BE, BF, CD, CE, CF
失敗
給
{A,B,C}{D,E,F}
你怎麼可能被Zsh/AWK解決這個問題?
單詞中的文件結合我有文件1無法被Zsh/AWK
A,B,C
和File2
D,E,F
我試圖通過
echo {`cat File1`}{`cat File2`}
有
AD, AE, AF, BD, BE, BF, CD, CE, CF
失敗
給
{A,B,C}{D,E,F}
你怎麼可能被Zsh/AWK解決這個問題?
awk -F, '
NR==FNR {
# read lines from File1 into the array f1
f1[NR]=$0
next
}
{
# foreach line in File2
split(f1[FNR], words); # get words from corresponding line in File1
sep = ""
for (i in words) {
for (j=1; j<=NF; j++) {
printf("%s%s%s", sep, words[i], $j)
sep = ", "
}
}
print ""
}
' File1 File2
如果file1包含
A,B,C
1,2,3
和File2包含
D,E,F
4,5,6
則AWK腳本輸出
AD, AE, AF, BD, BE, BF, CD, CE, CF
14, 15, 16, 24, 25, 26, 34, 35, 36
我不知道zsh的,這裏就是我所做的使用bash和sed:
echo "A,B,C" >a
echo "D,E,F" >b
for i in `cat a | sed -e "[email protected],@\[email protected]"`;
do for j in `cat b | sed -e "[email protected],@\[email protected]"`;
do echo -n "$i$j, ";
done ;
done | sed -e "[email protected],\s\[email protected]@"
輸出則是:
AD, AE, AF, BD, BE, BF, CD, CE, CF