sed command to replace \t(Tab) with '|'
I need to replace the tab(\t) in my text file to '|'.
command used: sed '/\\t/|/g' it replace all t with |. Please help me out. |
Tab is recognized as \t by SED. By escaping it, it now becomes just t. And you forgot to include the s in your SED command.
|
try this
Quote:
|
hi cbtshare,
When i used this code. cat infile 1234 test weye test1 break 576 test break title 2369 test line break tite break 234589 test like break sed -e 's/^[ \t]*/|/g' infile1 > aa.dat cat aa.dat |1234 test |weye test1 break |576 test break title |2369 test line break |ite break |234589 test like break Please let me know how to solve this. |
Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, bolding, colors, or other fancy formatting.
I've seen this happen before. Your file is probably set with dos-style line endings. You need to convert your files to unix-style endings for most *nix tools to work properly. sed can be used to convert the line endings at the same time. Just add a second expression to remove the extra carriage return. Code:
sed -e 's/\r$//' -e 'y/\t/|/' infile >outfile But actually, most of the time when you want to do this, tr is usually the preferred tool. Code:
tr -d '\r' <infile | tr '\t' '|' >outfile |
All times are GMT -5. The time now is 08:08 AM. |