Ever wonder’ed what’s the best way to indent all unindented files on your Linux machine. Well, although there is a program called GNU Indent that does this job of indentation, it’s probably not has handy as when you know it bit by bit.
Probably, the first thought that strikes us about how to do this is by simply typing
indent -kr -i8 *.c

However, pretty soon, you’ll realize that this method simply does not work.
The solution to this shall easy as cake, we can use concurrent processes to do the job like
for f in *.c
do
indent -kr -i8 $f &
done

This method, though works for a small number of files, its not good if the number of files is large, since memory is consumed by the concurrent processes.
The solution that I found was to do this in batches. For example :

limit=10
for f in *.c
do
indent -kr -i8 $f &
(( count = count + 1 ))

if [[ $count -eq $limit ]] then
wait
count=0
fi
done

Advertisements