Using sed to match regex -


i don't know sed, nor regex. want replace every line contains tabs string '0'. there lines in file contain '\n'.

basically want use regular expression ^\h+$ , replace matches 0.

i tried:

sed -i 's/^\h+$/0/' file.txt 

but doesn't work

you can use:

sed -i.bak -e 's/^[[:blank:]]+$/0/' file 

posix character class [[:blank:]] matches space or tab same \h in pcre.

-i.bak keep original file in file.bak, in case want restore.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -