我有一个包含此类数据的文件。
输入:
mstage1.service-ft.google.com:mstage1.service-ft.google.com
mstage1.service.google.com
mstage1.service.google.com:mstage1.service.google.com
mstage1.service-int.google.com
mstage1.serviceint.google.com
mstage1.service-int.google.com:mstage1.service-int.google.com
但是我想删除冒号,并且在冒号后面的下一个子域名应该出现在新行中。
输出:
mstage1.service-ft.google.com
mstage1.service-ft.google.com
mstage1.service.google.com
mstage1.service.google.com
mstage1.service.google.com
mstage1.service-int.google.com
mstage1.serviceint.google.com
mstage1.service-int.google.com
mstage1.service-int.google.com
如果你能帮我的话,谢谢,我对这类事情还不熟悉
答案1
猜测您想:
用回车符替换,只需使用流编辑器sed
:
sed 's|:|\n|g' /input/file.txt
学习更多关于sed
:https://linuxconfig.org/learning-linux-commands-sed
使用给定的样本数据:
user@host:~/Test$ cat ./input/file.txt
mstage1.service-ft.google.com:mstage1.service-ft.google.com
mstage1.service.google.com
mstage1.service.google.com:mstage1.service.google.com
mstage1.service-int.google.com
mstage1.serviceint.google.com
mstage1.service-int.google.com:mstage1.service-int.google.com
user@host:~/Test$
user@host:~/Test$ sed 's|:|\n|g' ./input/file.txt
mstage1.service-ft.google.com
mstage1.service-ft.google.com
mstage1.service.google.com
mstage1.service.google.com
mstage1.service.google.com
mstage1.service-int.google.com
mstage1.serviceint.google.com
mstage1.service-int.google.com
mstage1.service-int.google.com
但如果你想保留第一列(即删除之后的内容:
),那么使用cut
user@host:~/Test$ cut -d ":" -f 1 ./input/file.txt
mstage1.service-ft.google.com
mstage1.service.google.com
mstage1.service.google.com
mstage1.service-int.google.com
mstage1.serviceint.google.com
mstage1.service-int.google.com