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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -