[Nottingham] Re: Quick! I need a bash one liner!

James Gibbon jg at jamesgibbon.com
Tue Feb 1 16:05:38 GMT 2005


On Tue, 1 Feb 2005 15:31:02 +0000
Michael Erskine <msemtd at yahoo.co.uk> wrote:

> I'm fixing up some old C code and I want to expand the tabs in all the
> 
> files...
> 
> #!/bin/bash
> for file in *.[ch] 
> do
>  expand -t 4 $file > t1
>  mv t1 $file
> done
> 
> ...I guess this probably worked (not checked yet! I'd like to grep for
> '\t'  but it doesn't seem to act like perl and grep -P says "not
> supported") but  I'm curious whether this "script" can be issued as a
> one-liner - anyone?
> 


perl -p -i.bak -e "s|\t|    |g" *.[ch]

.. should do it. The old files are backed up as *.bak



More information about the Nottingham mailing list