Sponsored Content
Top Forums Shell Programming and Scripting Search multiple pattern in a file Post 302951214 by saurau on Tuesday 4th of August 2015 03:57:48 AM
Old 08-04-2015
Search multiple pattern in a file

I have a sample file with following output:

Code:
HTTP/1.1 200 OK
User: admin
Set-Cookie: AMBARISESSIONID=y3v3648yqcno32nq478kw7ar;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 6057
Server: Jetty(8.1.17.v20150415)

{
  "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN",
  "ServiceInfo" : {
    "cluster_name" : "XXXXX",
    "maintenance_state" : "OFF",
    "service_name" : "YARN",
    "state" : "STARTED"
  },
  "alerts_summary" : {
    "CRITICAL" : 7,
    "MAINTENANCE" : 0,
    "OK" : 2,
    "UNKNOWN" : 3,
    "WARNING" : 0
  },
  "alerts" : [
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/44",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 4,
        "definition_name" : "yarn_nodemanager_webui_percent",
        "host_name" : null,
        "id" : 44,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/57",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 8,
        "definition_name" : "yarn_nodemanager_webui",
        "host_name" : "eu-lamp-dev-m-0021-hadoop-slave01",
        "id" : 57,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/58",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 7,
        "definition_name" : "yarn_nodemanager_health",
        "host_name" : "eu-lamp-dev-m-0021-hadoop-slave01",
        "id" : 58,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/49",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 8,
        "definition_name" : "yarn_nodemanager_webui",
        "host_name" : "eu-lamp-dev-m-0022-hadoop-slave02",
        "id" : 49,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/50",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 7,
        "definition_name" : "yarn_nodemanager_health",
        "host_name" : "eu-lamp-dev-m-0022-hadoop-slave02",
        "id" : 50,
       "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/40",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 8,
        "definition_name" : "yarn_nodemanager_webui",
        "host_name" : "eu-lamp-dev-m-0023-hadoop-slave03",
        "id" : 40,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/41",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 7,
        "definition_name" : "yarn_nodemanager_health",
        "host_name" : "eu-lamp-dev-m-0023-hadoop-slave03",
        "id" : 41,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/2",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 2,
        "definition_name" : "yarn_resourcemanager_webui",
        "host_name" : "eu-lamp-dev-xl-0018-hadoop-master",
        "id" : 2,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/5",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 5,
        "definition_name" : "nodemanager_health_summary",
        "host_name" : "eu-lamp-dev-xl-0018-hadoop-master",
        "id" : 5,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/79",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 1,
        "definition_name" : "yarn_resourcemanager_rpc_latency",
        "host_name" : "eu-lamp-dev-xl-0018-hadoop-master",
        "id" : 79,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/80",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 6,
        "definition_name" : "yarn_resourcemanager_cpu",
        "host_name" : "eu-lamp-dev-xl-0018-hadoop-master",
        "id" : 80,
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/alerts/32",
      "Alert" : {
        "cluster_name" : "XXXXX",
        "definition_id" : 3,
        "definition_name" : "yarn_app_timeline_server_webui",
        "host_name" : "eu-lamp-dev-xl-0019-hadoop-sec-master",
        "id" : 32,
        "service_name" : "YARN"
      }
    }
  ],
  "components" : [
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/components/APP_TIMELINE_SERVER",
      "ServiceComponentInfo" : {
        "cluster_name" : "XXXXX",
        "component_name" : "APP_TIMELINE_SERVER",
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/components/NODEMANAGER",
      "ServiceComponentInfo" : {
        "cluster_name" : "XXXXX",
        "component_name" : "NODEMANAGER",
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/components/RESOURCEMANAGER",
      "ServiceComponentInfo" : {
        "cluster_name" : "XXXXX",
        "component_name" : "RESOURCEMANAGER",
        "service_name" : "YARN"
      }
    },
    {
      "href" : "http://XX.XX.XX.XX/api/v1/clusters/XXXXX/services/YARN/components/YARN_CLIENT",
      "ServiceComponentInfo" : {
        "cluster_name" : "XXXXX",
        "component_name" : "YARN_CLIENT",
        "service_name" : "YARN"
      }
    }
  ],
  "artifacts" : [ ]

I need to search any 2 or 3 patterns in above file e.g. UNKNOWN and CRITICAL,

I used the command $
Code:
awk '/UNKNOWN/ && /CRITICAL/ { print; }' <file_name>

But it is not working, Please help
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern search in multiple lines

Hi, I have to search those statements from the file which starts from "shanky"(only shanky, shanky09 or 09shanky is not allowed) and ends with ");". These two string can be in a same line or different line. And also i have to negate those lines which starts with #. Can any one please give me... (2 Replies)
Discussion started by: shanky09
2 Replies

2. Shell Programming and Scripting

How to pass multiple file types search pattern as argument to find?

How can I pass $var_find variable as argment to find command? test.sh var_find=' \( -name "*.xml" -o -name "*.jsp" \) ' echo "${var_find}" find . -type f ${var_find} -print # Below statement works fine.. I want to replace this with the above.. #find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies

3. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

4. Shell Programming and Scripting

Multiple pattern search in perl

user 10 values content is: musage.py yes value user 11 values content is: gusage.py yes value how to print "user" string line by searching "content is:" string and "usage.py" string in perl (8 Replies)
Discussion started by: Anjan1
8 Replies

5. Shell Programming and Scripting

Help need with PERL multiple search pattern matching!

My example file is as given below: conn=1 uid=oracle conn=2 uid=db2 conn=3 uid=oracle conn=4 uid=hash conn=5 uid=skher conn=6 uid=oracle conn=7 uid=mpalkar conn=8 uid=anarke conn=9 uid=oracle conn=1 op=-1 msgId=-1 - fd=104 slot=104 LDAPS connection from 10.10.5.6 to 10.18.6.5 conn=2... (3 Replies)
Discussion started by: sags007_99
3 Replies

6. Shell Programming and Scripting

Multiple search pattern

Hello :) I have this file cat employee_list Name : jack Gender: m ID : 4512 DOB : 03/27/1980 hire date : 04/23/2012 Nationality: US marital status : single ===================== Name : mick Gender: m ID : 1256 DOB : 03/27/1970 Hire date : 012/10/2011 Nationality: US Marital... (4 Replies)
Discussion started by: Sara_84
4 Replies

7. Shell Programming and Scripting

awk with multiple pattern search

Want to fetch a column with multiple pattern using awk. How to achieve the same. Tried cat test address : 10.63.20.92/24 address : 10.64.22.93/24 address : 10.53.40.91/24 cat test | awk '{print $3}' |awk -F "/" '{print $1}' 10.63.20.92 10.64.22.93 10.53.40.91 Is there any... (2 Replies)
Discussion started by: Manasa Pradeep
2 Replies

8. Linux

Search multiple pattern from list

I am working on AIX operating system. I want to search list of Article Id for given Set Date (which are present in a seperate file input.txt) art_list.csv ------------ "Article ID" |"Ad Description" |"Pyramid"|"Pyramid Desc "|"ProductTypeId"|"Set Date "|... (3 Replies)
Discussion started by: rajivrsk
3 Replies

9. Shell Programming and Scripting

Pattern search multiple files

#!/usr/bin/ksh a="Run successfully" cd $APPS ls -l *.txt | while read $txt do if then cp $APPS/$txt cp $hist/$txt else rm $APPS/$txt echo "Files has been removed" fi done New in shell script please help me out Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Discussion started by: Kalia
8 Replies
All times are GMT -4. The time now is 04:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy