题解 | #shell/bash转置文件的内容#
转置文件的内容
http://www.nowcoder.com/practice/2240cd809c8f4d80b3479d7c95bb1e2e
function solution1() {
awk '{printf $1 }' nowcoder.txt
awk '{printf $2 }' nowcoder.txt
}
function solution2() {
cut -d" " -f1 nowcoder.txt | tr -d "\n"
cut -d" " -f2 nowcoder.txt | tr -d "\n"
}
function solution3() {
local column_count=`head -n 1 file.txt | wc -w`
declare -A bigArray=();
local tempArray="";
local row_count=0;
while read line; do
tempArray=(${line})
bigArray[${row_count}]=${tempArray[@]}
((row_count++))
done < file.txt
for (( i=0; i<${row_count}; i++ )); do
for (( j=0; i<${column_count}; j++ )); do
echo ""
done
done
}
solution1