Blog of Timur Asaliev
RSS icon Email icon Home icon
  • Delete recursively lines from files that match a given string

    Posted on November 30th, 2009 Timur Asaliev No comments

    This is just a small snipplet to remind me of how to delete lines recursively that match a string needle

    #!/bin/sh
    grep -rl "needle" . |
    while read filename
    do
    (
    echo $filename
    sed '/needle/d' $filename> $filename.xx
    mv $filename.xx $filename
    )
    done

    References used:
    www.mehtanirav.com
    www.cs.mcgill.ca

    Leave a reply