Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在字段中查找公共值_Php_Linux_Shell_Unix - Fatal编程技术网

Php 在字段中查找公共值

Php 在字段中查找公共值,php,linux,shell,unix,Php,Linux,Shell,Unix,假设我有两个值为的文件: 文件A: name occupation grade ishaan doctor best sinha engineer worst palak sales good nishant commissioner best ishaan doctor good palak sales okey

假设我有两个值为的文件:

文件A:

name        occupation      grade
ishaan      doctor          best
sinha       engineer        worst
palak       sales           good
nishant     commissioner    best
ishaan      doctor          good
palak       sales           okey
文件B:

name        grade       occupation
ishaan      best        doctor
sinha       worst       engineer
palak       good        sales
nishant     best        commissioner
ishaan      good        doctor
palak       okey        sales

我想使用shell脚本只打印两个文件中字段占用中的公共值。如果您建议使用awk实用程序,那么也请解释该命令(带参数)

我认为这不是一个好答案,但你试试这个

运行循环获取记录,并使用array_push()将每个记录推送到一个新数组中


并检查(!in_array())是否不在数组中,然后显示新记录。

在终端中打印输出:

awk '{print $(NF-1)}'
awk '{print $(NF-1)}' /local/file/path > /output/file/path
将输出导出到文件:

awk '{print $(NF-1)}'
awk '{print $(NF-1)}' /local/file/path > /output/file/path
注意:NF--打印最后一个字段NF-1——打印最后一个字段-1


谢谢你的回复。但是它正在打印所有的值。。它没有给出常见的数字(我只需要这两个字段中的公共值…..是否有人协助此查询???我需要在上述行中找到公共值。