Simple solution with awk


  • 4
    J

    Simple solution with awk using associative array

    awk '{ for(i=1; i<=NF; ++i) {if (word[i] == "") {word[i] = $i} else{word[i] = word[i]" "$i}}} END{for(i=1; i<=NF; ++i) {print word[i]}}' file.txt


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.