commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Recursively find php files and replace tab characters with spaces.
"\*.php" -- replace this with the files you wish to find
"expand" -- replace tabs with spaces (use "unexpand" to replace spaces with tabs)
"-t4" -- tabs represent 4 spaces
Note: The IFS="" in the middle is to prevent 'read' from eating leading/trailing whitespace in filenames.
Tested with bash v4.1.5 on ubuntu 10.10
as written above, only works for programs with no file extention (i.e 'proggy', but not 'proggy.sh')
because \eb maps to readine function backward-word rather then shell-backward-word (which
is unbinded by default on ubuntu), and correspondingly for \ef.
if you're willing to have Ctrl-f and Ctrl-g taken up too , you can insert the following lines
into ~/.inputrc, in which case invoking Ctrl-e will do the right thing both for "proggy" and "proggy.sh".
-- cut here --
-- cut here --
Change the number to change the number of spaces. Leaving it out defaults to 8. Leaving out the filename defaults to stdin.
And to do it in reverse, you can use the unexpand command.
With this command you can use shell variables inside sed scripts.
This is useful if the script MUST remain in an external file, otherwise you can simply use an inline -e argument to sed.
Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification.
In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application.