Skip to content

Instantly share code, notes, and snippets.

@mcchae
Created October 7, 2015 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcchae/d33d629010469f09cf53 to your computer and use it in GitHub Desktop.
Save mcchae/d33d629010469f09cf53 to your computer and use it in GitHub Desktop.
exclude header lines
#!/bin/bash
usage()
{
echo "usage: $0 <folder> <matching_string> <n>"
echo " extract all first n header files from a file which is matching matching_string"
echo " ex) $0 . 'matching string' 15"
}
if [ $# -ne 3 ];then
usage
fi
FOLDER=$1
MSTR=$2
EXLINES=$3
for f in `find $FOLDER -type f`;do
grep "$MSTR" $f 2>/dev/null >/dev/null
if [ $? -ne 0 ];then
continue
fi
tail -n+$EXLINES $f > $f.tmp
mv -f $f.tmp $f
echo "Extract first $EXLINES lines from <$f>"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment