这是我编写的用于将所有海冰范围文件合并到一个文件中的UNIX代码。我尝试通过加入前两年然后创建一个for循环然后排除前两年所以它们不会被添加两次来做到这一点。它们仍然被添加两次。
#!/斌/庆典
#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
答案 0 :(得分:-1)
在if语句中我的文件名需要单引号。