my_leetcode/shell/q0194.sh

35 lines
563 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 194.转置文件
#
# [原题链接](https://leetcode-cn.com/problems/transpose-file/)
#
# 2021-07-16 10:06:30
#
# 给定一个文件 file.txt转置它的内容。
#
# 你可以假设每行列数相同,并且每个字段由 ' ' 分隔。
#
# 示例:
#
# 假设 file.txt 文件内容如下:
#
#
# name age
# alice 21
# ryan 30
#
#
# 应当输出:
#
#
# name alice ryan
# age 21 30
#
# Related Topics Shell
#
# 👍 52 👎 0
COUNT=`head -1 file.txt | wc -w`
for (( i = 1; i <= $COUNT; i++ )); do
awk -v arg=$i '{print $arg}' file.txt | xargs
done