【发布时间】:2020-08-27 15:24:46
【问题描述】:
我有以下数据,我想将冒号(:) 分隔值拆分到下一列
样本数据
htttp://example.com, 80
http://lookup/bin/search, 80
testecho345.unix.abc1200.org:8115,80
century.testing.external-abc03:6112,80
century.testing.external-abc03:6112,80
testecho345.unix.abc1200.org:8115,80
testecho345.unix.abc1200.org:8117,80
期望的输出
htttp://example.com, 80
http://lookup/bin/search, 80
testecho345.unix.abc1200.org,8115
century.testing.external-abc03,6112
testecho345.unix.abc1200.org,8117
注意:如果 http 则打印 80,https 则打印 443,如果 URL 中有任何数字,则打印该数字而不是 80
在 AWK 命令下尝试过,但没有得到预期的输出。
awk '{split($0,a,":"); print a[1],a[2]}'
同时删除重复项
提前感谢您的帮助。
【问题讨论】:
-
你有
split("|"..),而你应该有split(":",...)。祝你好运。 -
我也试过了,但没有运气@shellter
-
您希望
|如何拆分除以:的字段。请总是展示你最好的作品。您的意外输出是否与我在您的数据中看到的尾随,80有关?你也需要sub(/,80/,"", $0)。祝你好运。 -
你的输入是什么样的?
-
您也想删除原来的第二列吗?
cut -d, -f1 input.csv | tr : ,
标签: shell if-statement awk sed