leet-code/transpose-file/sol.sh

11 lines
266 B
Bash
Raw Normal View History

2021-11-08 21:18:55 +00:00
#!/bin/sh
lines=$(grep -oP '(?<![^ \n])[^ \n]+(?![^ \n])' file.txt)
n=$(sed "1q;d" file.txt | wc -w)
top=$(expr $n - 1)
for i in $(seq 1 $top); do
echo $(echo $lines | tr " " "\n" | awk "NR % $n == $i")
done
echo $(echo $lines | tr " " "\n" | awk "NR % $n == 0")