shell - extract information from file based on conditions -


b Please, I have a log file "log1.txt" in which the character "|" I want to retrieve the rows according to the specific requirements and I have another configuration file "code.conf" or I have put the values ​​found in field 5. Here is the log file:

+++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++ ABC | 2 | 11 | 3 | 1000 | 13. Scql | 0 | | | 0 | 0 | Plk | STV | 2 | 0 TRC | 2 | 20 | 3 | 1200 | 30 | Tkgl | 0 | Pajd | Jahd | 0 | 0 | Klm | Fdkl | 1 | 0 KLM | 2 | 0 | 3 | 1300 | 19 | Mlpo | 0 | | | 0 | 0 | Qnhd | Pkjs | 2 | 0 KLM | 2 | 20 | 3 | 1600 | 11 | Mlpo | 19 | | | 0 | 0 | Qnhd | Pkjs | 2 | 0

+++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++

And here the configuration file "code .conf "is

++++++++++++++++++++++++++++++++++++++++++++ +++ +++++++++++++++++++ 1000 1300 1200 1600

++ ++++++++++++++++++++++++++++++++++++++++++++ +

Now I want to get lines from the log file corresponding to this situation:

If field 2 equals "2" and field 4 is equal to "3" and field 5 should be one of the declared values ​​in the configuration file (field equal to "3" or "20" or "0") or fields 8 "0 is not equal to"

I tried it but it does not work properly:

  awk -F '* \\ | * '' FNR == NR {One [$ 1]; Next} $ 2 == 2 & amp; Amp; $ 4 == 3 & amp; Amp; $ 5 & amp; Amp; ($ 3! = 0 || $ 3 = 20) || $ 8! = 0 'file   

should be output:

  abc | 2 | 11 | 3 | 1000 | 13. Scql | 0 | | | 0 | 0 | Plk | STV | 2 | 0 KLM | 2 | 20 | 3 | 1600 | 11 | Mlpo | 19 | | | 0 | 0 | Qnhd | Pkjs | 2 | 0   

I think logic comes from reason

thanks

You have added your code to your code & amp; Amp; and || Use this:

  awk -F '* \\ | * '' FNR == NR {One [$ 1]; Next} $ 2 == 2 & amp; Amp; $ 4 == 3 & amp; Amp; $ 5 & amp; Amp; (($ 3! = 0 & amp; $ 3! = 20) || $ 8! = 0) 'code.conf file ABC | 2 | 11 | 3 | 1000 | 13. Scql | 0 | | | 0 | 0 | Plk | STV | 2 | 0 KLM | 2 | 20 | 3 | 1600 | 11 | Mlpo | 19 | | | 0 | 0 | Qnhd | Pkjs | 2 | 0    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -