#!/bin/bash if [ "$#" -ne 1 ]; then echo "Need to specify scenario output dir" exit fi cd $1 concatLcFile=lc_concat.txt concatPriceFile=price_concat.txt echo "Scenario,Year,Cropland,Pasture,ManForest,UnmanForest,Natural,FertCrop,FertPasture,IrrigCrop,IrrigPasture" > $concatLcFile echo "Scenario,Year,Crop,Imports,Exports,Price,Stocks" > $concatPriceFile find . -name "*lc.txt"|while read fname; do scenarioDir="$(dirname $fname)" scenario="$(echo $scenarioDir | sed 's,\.\/,,' | sed 's,\/,_,g')" echo "$scenario: $fname" i=1 while read -r line do test $i -eq 1 && ((i=i+1)) && continue echo "${scenario},$line" >> $concatLcFile done < $fname # Should write a function for this, rather than duplicating, but do that later j=1 while read -r line do test $j -eq 1 && ((j=j+1)) && continue echo "${scenario},$line" >> $concatPriceFile done < $scenarioDir/prices.txt done