gpt4 book ai didi

sed - 删除 () 前后的文本

转载 作者:行者123 更新时间:2023-12-04 06:28:48 25 4
gpt4 key购买 nike

如何删除文本直到第一个(和之后)?

INSERT INTO `todel` VALUES (1,'akbar\'s','Mumbai, Delhi road, India');
INSERT INTO `todel` VALUES (2,'amar\"s','South Africa, ghana');

预期的输出是这样的......
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'

最佳答案

ruby (1.9+)

$> ruby -ne 'print $_.sub(/.*\(|\).*$/,"")' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'

或 shell (bash)
$> while read -r line; do line=${line#*(}; echo ${line%)*}; done <file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'

或 awk
$> awk '{sub(/.*\(/,"");sub(/\).*/,"")}1' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'

或 sed
$> sed -rn 's/.*\(//;s/\).*//p' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'

关于sed - 删除 () 前后的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5701278/

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