我想使用 shell 脚本将矩阵转换为列表。谁能建议我使用 shell 来完成此操作?
矩阵是这样的
hello a|b
hi b|c
现在我想要一个像下面这样的矩阵:
hello a
hello b
hi b
hi c
有什么方法可以使用 shell 来实现吗?
提前致谢
最佳答案
这个命令:
awk -F'[| ]+' '{for(i=2;i<=NF;i++)print $1 "\t" $i}' file
将转换:
hello a|b|c
hi b|c|d
进入:
hello a
hello b
hello c
hi b
hi c
hi d
关于linux - 使用 Shell 脚本将矩阵转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39096797/