题解 | #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
全部评论
在windows上用vsc调试的时候,输出的字符串没有用空格隔开
点赞 回复 分享
发布于 2022-03-06 14:21

相关推荐

VirtualBoo...:都去逗他了?
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务