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!

PATTERN MATCHING PROBLEM

Status
Not open for further replies.

sachrath

Programmer
May 21, 2004
17
CH
Hi All,

I have a file in UNIX with 3 fields in it
A ,B C with their names.

I would like to search for all the values in the file for which
A is NULL and B is not NULL
and
again
A is NOT NULL and B is NULL .

NULL refers to a blank value within the delimiters which is '|' in this case.

Any help is appreciated.

Thx
Sachin
 
If NULL refers to an empty field:
awk -F'|' '($1=="" && $2!="") || ($1!="" && $2=="")}' /path/to/file
If NULL refers to a blank field:
awk -F'|' '($1==" " && $2!=" ") || ($1!=" " && $2==" ")}' /path/to/file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thx ,

We have some standard UNIX scripts prepared which works only with EGREP , so I need to pass the search criterion in PATTERN MATCH.

The characters like '=' & '!=' doesnt work in pattern match .

Thx
Sachin Rath.
 
A is NULL and B is not NULL
'^ *\|[^ |]'
A is NOT NULL and B is NULL
'^[^ |]+\| *\|'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Thx once again , it is working , but could not understand why '+' is used within the search string.
Chao
Sachin
 
+ means at least one occurrence of preceding expression.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top