This is from a program I wrote a while ago for someone.
Code:
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <frob23@yahoo.com> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. Eric F.
# ----------------------------------------------------------------------------
BEGIN {
FS="|";
notfound=1
}
{if ($3 == id)
{ print newline; notfound=0}
else {print $0}
}
END {if (notfound==1)
print newline
}
Here is the snippet that calls it.
gawk
-v id="$ID" -v newline="$LINE" -f updatedata.awk tmpfile >tmp
I hope that helps a little.
Edit: Pay special attention to the
bold segments as they should give you an ample hint as to how to do this.