这是我写的unix代码,将所有海冰范围文件加入一个文件。我试图通过加入头两年来做到这一点,然后创建一个for循环,然后不包括前两年,以免添加两次。他们仍被添加两次。
#!/bin/bash
#this creates the file output_extent initially but then the if statement in the following loop does not work and there are two columns for 1979 and 1989
join polar_ice_extent_data.1979.txt polar_ice_extent_data.1980.txt > output_extent.txt
#for loop with an if statment to join all files that include extent except the first two into a new file.
#Have to create a temporary file because it will not append back onto output_extent directly
for file in *extent*.txt; do
if [ $file != polar_ice_extent_data.1979.txt ] && [ $file != polar_ice_extent_data.1980.txt ]; then
join output_extent.txt $file > tmp.txt; mv tmp.txt output_extent.txt;
fi
done
文件示例:重复1979-2015
#year 1979
jan 15.6
feb 16.38
mar 16.52
apr 15.56
may 14.08
jun 12.65
jul 10.52
aug 8.18
sep 7.22
oct 9.42
nov 11.18
dec 13.57
它在if语句中需要围绕我的文件名的单引号标记。