Linux 从两个不同的文本文件中读取并获取每一行';s柱

Linux 从两个不同的文本文件中读取并获取每一行';s柱,linux,shell,unix,sh,Linux,Shell,Unix,Sh,我想从两个不同的文本文件(行号相等)中读取数据,并将每行的第5列相互比较。但这对我不起作用。有人帮我吗?这是我的代码: df -h --total>current_filesystem_usage.txt if [ -s previous_months_filesystem_usage.txt ] then #reading from two different files and store each line into a variable while read curr

我想从两个不同的文本文件(行号相等)中读取数据,并将每行的第5列相互比较。但这对我不起作用。有人帮我吗?这是我的代码:

df -h --total>current_filesystem_usage.txt
if [ -s previous_months_filesystem_usage.txt ]
then 
  #reading from two different files and store each line into a variable
    while read current_file_line <&3 && read previous_file_line <&4
     do

    current_filesystem_name=$(cat $current_file_line | awk {'print $1'})
    current_filesystem_usage=$(cat $current_file_line | awk {'print $5'})

    previous_filesystem_name=$(cat $previous_file_line | awk {'print $1'})
    previous_filesystem_usage=$(cat $previous_file_line | awk {'print $5'})

    if [ ${current_filesystem_usage%?} -ge ${previous_filesystem_usage%?} ]
           then echo "There is problem !!! "
            echo "Current disk usage:${current_filesystem_name}, ${current_filesystem_usage}"
            echo "Previous month's disk usage:${previous_filesystem_name}, ${previous_filesystem_usage}"
        #I also want to store all echo output to output.txt file

    elif [ ${current_filesystem_usage%?} -lt ${previous_filesystem_usage%?} ]
             then echo "There is no problem. Everything is alright."
              echo "Current disk usage: ${current_filesystem_name}, ${current_filesystem_usage}"
              echo "Previous month's disk usage: ${previous_filesystem_name}, ${previous_filesystem_usage}"
       fi

         done 3<current_filesystem_usage.txt 4<previous_months_filesystem_usage.txt

fi
df-h--total>current\u filesystem\u usage.txt
如果[-s以前的\u个月\u文件系统\u usage.txt]
然后
#读取两个不同的文件,并将每行存储到一个变量中
在awk中读取当前\u文件\u行时:

$ awk '
NR==FNR {               # process the first file
    a[FNR]=$5           # hash field $5 to a, use row number as key
    next }              # move to next record
$5 > a[FNR] {           # process the second file, if current is greater than previous
    print "error"       # output error
}
' file1 file2

它基本上将file1散列到
a
,并使用行号作为键。您在帖子中没有提到比较结果是什么,因此无法帮助更多的ATM。

您能解释一下吗?例如,a是什么?为什么以$0开头?比较的结果,如果当前值大于以前的回显错误,如果不是,则一切正常。
a
是一个哈希,在处理
file1
时,
5
存储在其中,行号作为键。非常感谢您的努力。我真的很感激。我会试试。如果有更好的要求,我可能会提供更多帮助。如果您想比较和计算差异,可以使用not
-m
而不是
-h
。它将以兆字节的形式输出结果作为整数值,而不是人类可读但解析不好的形式。不是兆字节,兄弟。