문제

If the character is met more than once I must replace it with a single one. For example i have this in a file: ????aca, I must replace it with ?aca. I've tried it with tr, but didn't make it to work proper.

도움이 되었습니까?

해결책

It seems easy with using backreferences:

sed 's/\(.\)\1\+/\1/g' infile

다른 팁

If you want to truncate consecutive runs of one particular character, tr -s does that.

tr -s '?' <file >file.new

Based on your limitation to ?

sed 's/[?]\{2,\}/?/g' YourFile

also POSIX compliant

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top