File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 55<!-- |@home https://github.com/openset/leetcode |-->
66<!-- +----------------------------------------------------------------------+-->
77
8+ [ < Previous] ( https://github.com/openset/leetcode/tree/master/problems/valid-phone-numbers " Valid Phone Numbers ")
9+
10+ [ Next >] ( https://github.com/openset/leetcode/tree/master/problems/tenth-line " Tenth Line ")
11+
812## 194. Transpose File (Medium)
913
1014<p >Given a text file <code >file.txt</code >, transpose its content.</p >
Original file line number Diff line number Diff line change 1+ name age
2+ alice 21
3+ ryan 30
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Read from the file file.txt and print its transposed content to stdout.
4+
5+ awk '
6+ {
7+ for (i = 1; i <= NF; i++) {
8+ if(NR == 1) {
9+ s[i] = $i;
10+ } else {
11+ s[i] = s[i] " " $i;
12+ }
13+ }
14+ }
15+ END {
16+ for (i = 1; s[i] != ""; i++) {
17+ print s[i];
18+ }
19+ }' file.txt
You can’t perform that action at this time.
0 commit comments