A nice little catch-22 situation for you.
If you use single quotes (') then the shell variables will not be expanded. So at the point where you have '$1 == $id' the shell has not expanded the shell variable "id", and awk has no idea what "id" is.
Unfortunately if you try to use double quotes (") then the shell will expand the "id" variable, but it will have no clue what the $1 should be expanded to.
One solution is to explicitly pass the variable to awk:
awk -F "|" -v MyID="$id" '$1 == MyID {print}' data | cut -d "|" -f2
Note that you can actually reuse the variable name (although doing so can confuse some people while simultaneously making it easier for others to read)
:
awk -F "|" -v id=$id '$1 == id {print}' data | cut -d "|" -f2
An alternative way of doing this would be to make id an environmental variable:
export id=5678
Now you can access it through the ENVIRON array:
awk -F "|" '$1 == ENVIRON["id"] {print}' data | cut -d "|" -f2
Regards, Andrew
[ May 27, 2008: Message edited by: Andrew Monkhouse ]