tabs converted to spaces?

Leo de Wit leo at philmds.UUCP
Wed Jul 20 01:54:04 AEST 1988


In article <187 at alobar.ATT.COM> grs at alobar.att.com (Gregg Siegfried) writes:
>In article <3940001 at hpgrla.HP.COM> douglasg at hpgrla.HP.COM (@Douglas Genetten) writes:
>>Is there a filter which converts tabs to n-spaces throughout
>>a file?
>
>I've found that tr(1) does a pretty good job of this.  If you're printing
>the file, pr(1) also does what you need.

Tr translates characters, and will thus generally not do what Douglas
wants it to: n-spaces. All you could do with tr is translate each tab
into a (1) space (unless you know something about tr that I do not).
Pr does too much, unless indeed all you want to do is format the file.

Two alternatives: if you want the filter to know of tabstops (thus
expanding into spaces until the next tabstop) use expand (and to
reverse: unexpand); you can even use your favourite tabstop sequence.
If you just want to replace each tab by a certain constant number of
spaces, you could use sed:

      sed 's/	/    /g' your_tab_file >your_space_file
             ^	 ^^^^
           TAB	 your n spaces.

Enjoy!

        Leo.



More information about the Comp.unix.questions mailing list