Shell行列转换

1. 转换行到列
examlpe files:
aaa.txt;bbb.txt; ccc.txt

cat filename | tr '; ' '\n'|sed 's/[ ]//g'


output:

aaa.txt
bbb.txt
ccc.txt


**sed 's/[ ]//g'消除space

2. 转换列到行
假设有个文件test.dat,其文件内容为:

line1
line2
line3

现在想将其转换为line1|line2|line3

cat test.dat | tr '\n' '|' | sed -e 's/|$/\n/'

猜你喜欢

转载自luocb1980.iteye.com/blog/969783
今日推荐