Posts mit dem Label shell werden angezeigt. Alle Posts anzeigen
Posts mit dem Label shell werden angezeigt. Alle Posts anzeigen

Mittwoch, 13. April 2011

Shell-004: Selective Listing

Given the case that a number of files are in a directory, file-test.py and at the same time there is a directory called file-test in the same directory. How can only the directories be listed? This is useful when the content of the directories needs to be processed somehow.

ls -l|grep ^d|awk '{print $8}'

Grep matches the beginning of the line output by 'ls' with 'd', which indicates a directory. " 'awk {print $8}' " then prints the 8th column of the output (so the directory name is available again).

Freitag, 8. April 2011

Vim 002: Submitting Vim Command from the shell

A Vim command can be submitted to Vim directly from the shell (without entering Vim) by calling:
vi "+:%s/+0/+1/g" "+wq" $i

Notice the '+' operator within the command string. Also notice the 'wq' command to save and "exit" Vim once it finished its job. This is an excellent way of processing a batch of files.