Computing.Net > Forums > Unix > replacing a character with a tab

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

replacing a character with a tab

Reply to Message Icon

Name: hernandez
Date: May 4, 2003 at 03:03:02 Pacific
OS: xp / korn shell
CPU/Ram: 196
Comment:

Hi,

I have some data which is comma delimited. How do I change it to be tab delimited?

I tried sed 's/,/\t/g' but it just replaced the commas with a t.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 4, 2003 at 09:56:34 Pacific
Reply:

Hi:

One way is to actually embed the special tab character in the sed string. In vi, this is done by pressing the control-v followed by the tab character:

sed 's/,/ /g' data.file

Obviously, you can NOT cut-and-paste such a line. Instead, consider embedding the octal value of the tab character, 011, inside the sed command:

sed 's/,/'"$(printf '\011')"'/g' data.file

Yes, the embedded quotes are important. The echo command works as well, but I prefer printf for portability:

sed 's/,/'"$(echo '\011')"'/g' data.file

Regards,


Nails



0

Response Number 2
Name: hernandez
Date: May 5, 2003 at 13:19:03 Pacific
Reply:

ta very much


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: replacing a character with a tab

How to replace a string w/ var www.computing.net/answers/unix/how-to-replace-a-string-w-var/7439.html

count the occurence of a char in a string www.computing.net/answers/unix/count-the-occurence-of-a-char-in-a-string/8516.html

how to replace a line in a file www.computing.net/answers/unix/how-to-replace-a-line-in-a-file/7214.html