Wiki

Clone wiki

scl-manips-v2 / help / bash-help

Change an expression in a bunch of files

for foo in `find . -name '*obj' -type f`;
do
cat $foo | sed s/mtllib/bobo/g > foo2;
echo Updating $foo;
mv foo2 $foo;
done

The ; replaces an enter if you want to type it all in the same line. You might have to clean up some junk later: for foo in `find . -name foo2`; do rm $foo; done

Change an expression in a bunch of files (advanced ops/use cut+grep to find regex str)

for foo in `find . -name '*obj'`;
do
ls $foo | xargs grep mtllib | cut -d ' ' -f 2 > foo2;
cat $foo | sed s/`cat foo2`/Skeletor.mtl/g > foo3;
echo Updating `cat foo2` in $foo to Skeletor.mtl;
mv foo3 $foo;
done

Print the names of files that contain a certain expression

for foo in `find . -name '*'`;
do
echo $foo | sed s/sUtil0.1/sUtil/g > foo2;
echo Updating $foo;
mv foo2 $foo;
done

Find the files that contain a string

find . -name "*<filetype>" | xargs grep '<string>'
Change a bunch of file names (replace a string in them) :
for foo in `find . -name '*.*'`;
do
echo $foo | sed s/<old_filename_substr>/<new_fn_substr>/g > foo2;
echo mv $foo `cat foo2`;
mv $foo `cat foo2`;
done

Updated