gpt4 book ai didi

linux - 如何使用 cut 和 grep 在 unix 中打印一系列字符?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:34 26 4
gpt4 key购买 nike

我可以使用 (cut -d) 指定分隔符来打印字符 block 。

# grep -i access.log| grep ' 500 '| cut -d\- -f1 

但是如何在特定模式“address=tel%3A%2B”之后打印字符

例如:如何打印这个文件中的所有电话号码?

begining of the line address=tel%3A%2B416xxxxxxx rest of the log
begining of the line address=tel%3A%2B647xxxxxxx rest of the log
begining of the line address=tel%3A%2B519xxxxxxx rest of the log

...

最佳答案

我尝试使用 cut -c 来打印行中特定位置的字符,它起作用了,因为大多数行都遵循相同的模式。直线的位置从1开始。

# grep -i test.log| grep ' 500 '|cut -c1-5 

这里1:是字符的起始位置。

此处 5:要打印的最后一个字符的位置。

所以例如如果:

#cat test.log
this is address=tel%3A%2B416xxxxxxx
this is address=tel%3A%2B647xxxxxxx
this is address=tel%3A%2B519xxxxxxx

#cut -c26-36 test.log
416xxxxxxx
647xxxxxxx
519xxxxxxx

关于linux - 如何使用 cut 和 grep 在 unix 中打印一系列字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36501700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com