shell 脚本之转置文件

Given a text file file.txt, transpose its content.

You may assume that each row has the same number of columns and each field is separated by the ' ' character.

Example:

If file.txt has the following content:

name age
alice 21
ryan 30

Output the following:

name alice ryan
age 21 30

看例子,其实要做的事情很清楚吧,然后可以用 awk(awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息) ,来看看怎么写,下面这种写法也是我第一次见。

awk '{ for(i=1; i<=NF; ++i) {if (word[i] == "") {word[i] = $i} else{word[i] = word[i]" "$i}}} END{for(i=1; i<=NF; ++i) {print word[i]}}' file.txt

当然中间有个小插曲,因为我想在阿里云的机器上试试,结果老是显示

5a39fd09f33e62b7b9bf41ae0c611fba441.jpg

那我用 ssh -v 试试,打印出 debug 信息,毫无进展

f92ba7a843bf5e87194370b2a7d4be1d951.jpg

然后就是查看  /etc/hosts.allow 和 /etc/hosts.deny 看里面有没有配置信息,因为大家都说是启用了 TCP Wrapper  访问控制所致

9e92e9bbc042a961c5aa0df9767804d4b58.jpg

但是里面什么信息都没有,放弃了,不是这个问题

然后也说了很多连接数的问题,其实我都知道这个不会是,因为就我自己玩呀,可以用lsof -i:22 看看

9301d424f39d846d568dc101966393e5b92.jpg

什么都没有改变,那到底什么不一样吗,我觉得只能是网络了,果然用了手机的热点,就可以访问了,但是我们公司的网络又做了什么事情呢?

转载于:https://my.oschina.net/u/2277632/blog/1835374

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值