Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a text file like this:

info  Some info here

In which when I use cat -A display this:

info^I Some info here

How do I edit this so I'll get something like this instead:

info<space>-<space>Some info here
share|improve this question

1 Answer 1

up vote 5 down vote accepted
sed 's/\t/ -/' inputfile

if that pattern appears multiple times on a line, use the global option:

sed 's/\t/ -/g' inputfile

if you want to restrict it to certain lines, for example that start with "info":

sed '/^info/ s/\t/ -/' inputfile

You can use the -i option to edit the file in place:

sed -i 's/\t/ -/' inputfile

If you don't do that you can do this equivalent operation

sed 's/\t/ -/' inputfile > outputfile && mv outputfile inputfile
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.