Monday, July 28, 2008

[code] sed, awk, and tab

Never realized that sed doen't recognize tab as a escape character. So to use regular expression to search and replace tab characters out of a file, use awk instead.

With sed (very dangerous to put tab character like this because it's easy to accidently copy and paste, and turn tab into space):

sed -e 's/ /x/g' myfile.txt

Better with awk:

awk '{gsub("\t","x");print}' myfile.txt