Using grep for a particular field

Hi ,

I have a file as shown below :

1836       21000    01052019             BH90P.TEMP.DA1836.FTP             W            NULL                                    S		
1836       22000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/21000                              S		
1836       23000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/22000                              S		
1836       24000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/23000                              S		
1836       25000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/24000;1801/24000;2248/24000        S		
1836       26000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/25000                              S				
1836       27000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/26000                              S		
1836       ETL31    01052019             BH90P.TEMP.DA1836.FTP             W            1836/27000                              S		
1836       ETL32    01052019             BH90P.TEMP.DA1836.FTP             W            1836/ETL31                              S	

When i use egrep "1836/2400|1836/2500|1836/2700" <filename> it will print below mentioned line:

1836       25000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/24000;1801/24000;2248/24000        S		
1836       26000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/25000                              S			
1836       ETL31    01052019             BH90P.TEMP.DA1836.FTP             W            1836/27000                              S

i want that it will not print "

1836       25000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/24000;1801/24000;2248/24000        S

" if further values 1801/24000 and 2248/24000 is not taken during egrep. But if all the values are present during egrep then it will print the line.

Make it

egrep " (2248/24000|1836/25000|1836/27000) " file

, then.For your second condition, you'll need to specify the entire pattern:

egrep "1836/24000;1801/24000;2248/24000|(1836/24000|1836/25000|1836/27000) " file
1836       25000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/24000;1801/24000;2248/24000        S        
1836       26000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/25000                              S                
1836       ETL31    01052019             BH90P.TEMP.DA1836.FTP             W            1836/27000                              S        

Match only in field #6, match the whole field:

awk '$6 ~ ("^(" search ")$")' search="1836/24000|1836/25000|1836/27000" file

Compare with the following, matching a whole ";" separated sub field:

awk '(";" $6 ";") ~ (";(" search ");")' search="1836/24000|1836/25000|1836/27000" file