Skip to content

Commit 78e07f7

Browse files
committed
Add: Transpose File
1 parent 9c2157e commit 78e07f7

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: problems/transpose-file/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
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>

Diff for: problems/transpose-file/file.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name age
2+
alice 21
3+
ryan 30

Diff for: problems/transpose-file/transpose_file.bash

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

0 commit comments

Comments
 (0)