我有两个档案:
档案1
*Name|Date|id|Total*
Jimmy|03-OCT-18|BST100114262|20000
Dedi|03-OCT-18|BST100904288|10000档案2
*Name|Amount*
Anton|9800
Jimmy|90000输出:吉米-20000/90000-1800000000
我试过了,但没有运气。
awk -F'|' 'NR==FNR{a[$1]=$1; next} (($1 in a) && (a[$4] >= $2 )) { print a[$4]*$2 }'发布于 2018-10-29 06:43:31
另一个:
$ awk 'BEGIN{FS=OFS="|"}($1 in a)&&FNR>1{print $1,a[$1],$NF,a[$1]* $NF}{a[$1]=$NF}' file1 file2产出:
Jimmy|20000|90000|1800000000解释了一些用金米:
$ awk '
BEGIN { FS=OFS="|" } # set separators
($1 in a) && FNR>1 { # if key to hash (Jimmy) is in a excluding headers
print $1,a[$1],$NF,a[$1]* $NF # process Jimmy
# next # this excludes new Jimmy from being rehashed to a
}
{
a[$1]=$NF # ... in here where everything is hashed and the
}' file1 file2 # ... existing rehashedhttps://stackoverflow.com/questions/53038251
复制相似问题