I am new to sed, so want to know how can I match tab. I have some text like this -
    line one {
            line two {
                    filler {
                            text value
                    }
                    line four
            }
    }
I am using the expression, which matches the above text if there are no tabs.
sed -i -e "/ line two {/,/}/s/text .*\$/text new/" $file
However, there are 2 tabs before "line two" and 3 tabs before "filler" and 4 tabs before "text value".
Any help?
In GNU sed, tabs are represented as \t.  So, the substitution will be successfully made with the following:
sed -i -e "/\tline two {/,/}/s/text .*\$/text new/" "$file"
The only required change was to replace / line two {/ with /\tline two {/.  The command /s/text .*\$/text new/ does not require any change because it does not attempt to match the white space that precedes text.  If there might be a tab that follows text, then use:
sed -i -e "/\tline two {/,/}/s/text[[:space:]].*\$/text new/" "$file"
If you are unsure of what white space character will appear, the expression [[:space:]] can be used to match any kind of white space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With