Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep-ping Multiple Values in a Record

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a pipe delimited file that contains lines I need to exclude (using the -v flag) from my processing. If it were any one of multiple values, no sweat - I do that already.

However, this particular instance involves pulling (or ignoring) any line which contains all three specified values.

Example: if the line has 'v1, 'v2' and 'v3' in it, I want to ignore it ... if it has any combination of two of these, or any one of them by itself, I want to keep it.

Thoughts?

Thanks as always in advance for the assistance.

Tom

"My mind is like a steel whatchamacallit ...
 
man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
If you know what field v1,v2,v3 are always in, I would try something like this:

Code:
#!/bin/sh
#
for LINE in `cat /your/filename`
  do
      DISCARD=`echo ${LINE} | awk -F"|" `{ print $FIELD1,$FIELD2,$FIELD3 }`
      if [ "${DISCARD}" = "v1v2v3" ] ;
        then
             echo ${LINE} >> /new/filename
        else
             echo ${LINE} > /dev/null
      fi
  done
# End

Resume online at:
 
Thanks, guys. I figured out that I'm going to have to awk out the patterns ... will work on it tomorrow at work when I'm almost awake (had an all-nighter upgrade last night, not even sure of my own name right now ... :))

Appreciate it!

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top