Thursday, March 14, 2013

Using awk to remove lines from a file

A little goodie I'm writing up here to document for my own future reference.

Objective: Remove all lines matching a certrain pattern from all files in a directory structure. The pattern is in the form of "part1.<alnum>.part2"

First try: grep and sed, unfortunately that leaves me with blank lines where the matching content was and I want that line removed completely. Apparently sed can't do that.

Second try: use awk with regexes. It took me a while and I wanted to use 'next' on matching lines but that didn't seem to work so I ended up printing the entire line if the regex didn't match. Here goes:

Loading ....

No comments:

Post a Comment