![添加 Q + 列号作为 x 列的标题](https://linux22.com/image/1540817/%E6%B7%BB%E5%8A%A0%20Q%20%2B%20%E5%88%97%E5%8F%B7%E4%BD%9C%E4%B8%BA%20x%20%E5%88%97%E7%9A%84%E6%A0%87%E9%A2%98.png)
答案1
所以,这就是我想到的办法。有点混乱,我想可能有更快的方法,但这个办法有效。
for i in $(seq 1 $maxPops); do echo $i; done > output1.txt #make a temp file with numbers 1 to max populations maxPops
awk '{for (i=1;i<=NF;i++) {print "Q"$i;}}' output1.txt > outpu2.txt #Add Q to the beginning of each row name
cut -f1 output2.txt | paste -s > output3.txt #transpose the row names
awk -v OFS="\t" '$1=$1' inputPopFile.txt > chosenPop.txt #change single spaces to tab delimited spaces
cat output3.txt chosenPop.txt > renamedColumns.txt #add formatted column names to desired file chosenPop.txt
rm $fastStructure/temp1.txt $fastStructure/numPops.txt #remove unwanted files