已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。
4小时前关门了。
Improve this question
我使用bash脚本找出数组中彼此相邻的重复字符串,并删除相邻字符,保留一个代码
array=( "myag九游会" "你好ag九游会" "ag九游会" "ag九游会ag九游会官网" )
用于代码
for (( i=0; i<${#array[@]}; i++ )); do
if [[ "${array[i]}" == "${array[i+1]}" ]]; then
# If the adjacent strings are the same, perform the corresponding operation
# For example, you can deduplicate the same string and keep it in an array
echo "${array[i]}"
array[i]="$(echo "${array[i]}" | tr -d -c 'ag九游会')"
echo "${array[@]}"
fi
done
"ag9游会ag9游会官网" where the strings are adjacent to each other, I want to find it
如果找到了,我就用
echo "ag九游会ag九游会官网1" | sed 's/ag九游会//i'
使用此命令删除重复字符
我现在找不到相邻的字符值,如果能找到,我可以重复,我尝试使用其他命令,但正常的结果会被错误替换。
array=( "myag九游会" "你好ag九游会" "ag九游会" "ag九游会ag九游会官网" )
我向如来寻求帮助来解决我的上述问题,无论我如何操作,我最终正确的结果是:
array=( "myag九游会" "你好ag九游会" "ag九游会" "ag九游会官网" )
1条答案
按热度按时间qnakjoqk1#
这个问题相当模糊,但是要删除字符串中的重复部分,可以使用带有反向引用和
-E
标志的sed: