Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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
Linux 检查两个不同文件中的字段是否不相等_Linux_Bash_Shell - Fatal编程技术网

Linux 检查两个不同文件中的字段是否不相等

Linux 检查两个不同文件中的字段是否不相等,linux,bash,shell,Linux,Bash,Shell,我正在尝试创建一个脚本,该脚本读取用户信息,如果有任何更改,将从原始文件更新变量。如果一个变量为空,我想省略它,基本上,我想保持这个变量不变 我正在编写的两个文件中的数据格式如下: Nickname FirstName LastName Hobbies occupation currActive Inactive YearsOld lucky number The original file looks like this: WebCrawler Peter Parker dancing fi

我正在尝试创建一个脚本,该脚本读取用户信息,如果有任何更改,将从原始文件更新变量。如果一个变量为空,我想省略它,基本上,我想保持这个变量不变

我正在编写的两个文件中的数据格式如下:

Nickname FirstName LastName
Hobbies
occupation currActive Inactive
YearsOld
lucky number

The original file looks like this:
WebCrawler Peter Parker
dancing fishing
student 08/09/2019 12/14/19
20
9

Example of the new data read and saved as a temp file is:
WebCrawler Peter Parker
reading movies dancing
Software Jr developer
24
777

忘了提到我没有使用grep、sed或awk

为什么业余爱好没有更新呢?在新文件中不同。嘿@Shawn,因为当读取爱好并包含空白输入时,变量保持不变,但它不是空的?
我是stdout
-你是stdout?标题行也是输入的一部分吗<代码>保留未更改的变量-哪些变量应保持不变?难道你不能用新数据覆盖文件吗?如果你知道了,就发布一个答案。
read NickNameTemp
read FirstNamTemp
read LastNameTemp
read HobbiesTemp
read Tempoccupation
read TempcurrActive 
read TempInactive
read TempYearsOld
read Templucky number

Tempfilename=${NickNameTemp}.backup
if [ ! -f $Tempfilename ]; then
    echo "ERROR: course not found"
    exit 1
fi

compareFunction(){
count=1
# here is where my logic is messed up 

while read a b c ; do
if [[ b != FirstNamTemp && c !=LastNameTemp ]]; then
   echo "$a $FirstNameTemp $LastnameTemp " > a.original
fi
count+=1
done
}

compareFunction < NickName.original

WebCrawler Peter Parker
dancing fishing
Software Jr developer
24
777