Sed syntax to remove 2 characters only when it is box and space

sed

I have a sed expression to remove the first 2 characters from all the lines in a file.

sed 's/^..//' raw.txt > converted.txt

However, the problem is some lines are large and get appended to the next line. For example,if I consider the input as in the below lines,

□ I have box and space in front
□ I am a large line which will
get appended to next line.
□ I am another line.

As per my sed syntax, I am getting the output as,

I have box and space in front
I am a large line which will
t appended to next line. 
I am another line. 

However, the output am expecting is,

I have box and space in front. 
I am a large line which will get appended to next line. 
I am another line. 

How should I modify the sed expression to achieve this?

Best Answer

awk '
    {
        if (/^□ /) {
            if (prev_line) 
                print prev_line
            prev_line = substr($0, 3)
        } else {
            prev_line = prev_line " " $0
        }
    }    
    END {print prev_line}
' raw.txt
I have box and space in front
I am a large line which will get appended to next line.
I am another line.
Related Question