Sponsored Content
Top Forums Shell Programming and Scripting Grep a part of file based on string identifiers Post 302783207 by vivek d r on Wednesday 20th of March 2013 06:15:02 AM
Old 03-20-2013
Grep a part of file based on string identifiers

consider below file contents

Code:
cat myOutputFIle.txt
8 CCM-HQE-ResourceHealthCheck:
Resource List :
No RED/UNKNOWN resource Health entries found
----------------------------------------------------------
9 CCM-TraderLogin-Status:
Number of logins: 0
----------------------------------------------------------
10 CCM HA Status:
Server:XXX.XX.XX.XX not enabled
Server Role:ACTIVE
Server State:AVAILABLE
Network State:GY_PY
----------------------------------------------------------
11 MG-DigitalPortChannel-Status:
No MG's are present hence terminating script
----------------------------------------------------------
12 MM-Operational-State:
HTML Code:
ipAddress       requestOperationalState
XX.xx.XX.XX.XX   MS_INTRAFFIC
----------------------------------------------------------


what i want to achieve is grep a string let say "CCM HA Status:" and display all the lines below it till it reaches "-----------------------------------------"

i implemented partially using sed command. .but its displaying output allong with identifiers..

Code:
[root@htmlgen]# sed -n "/CCM HA Status:/,/----------------------------------------------------------/ w tablextract2.sql" <myOutputFIle.txt
[root@ htmlgen]#
[root@duhtmlgen]# cat tablextract2.sql
10 CCM HA Status:
Server:xxx.xx.xxx.xxHA not enabled
Server Role:ACTIVE
Server State:AVAILABLE
Network State:GY_PY
----------------------------------------------------------
[root@ htmlgen]#


what the expected output is

Code:
Server:xxx.xx.xxx.xxHA not enabled
Server Role:ACTIVE
Server State:AVAILABLE
Network State:GY_PY

similarly if i search for "MM-Operational-State:" it should display below output

Code:
ipAddress       requestOperationalState
XX.xx.XX.XX.XX   MS_INTRAFFIC

any help is appreciated.. thanks

Last edited by vivek d r; 03-21-2013 at 01:27 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sort entire line based on part of the string

hey gurus, my-build1-abc my-build10-abc my-build2-abc my-build22-abc my-build3-abc basically i want to numerically sort the entire lines based on the build number. I dont zero pad the numbers because thats "how it is" ;-) sort -n won't work because it starts from the beginning. ... (10 Replies)
Discussion started by: gurpal2000
10 Replies

2. Shell Programming and Scripting

Need Awk command to get part of string based on delimeter

HI, Need awk command to get date and time alone from Input : "15:29:15 28.08.2010|SCHEDULE: Started program POSG1" Output expected : "15:29:15 28.08.2010" Please help. (9 Replies)
Discussion started by: shanneykar
9 Replies

3. Shell Programming and Scripting

Extracting few lines from a file based on identifiers dynamically

i have something like this in a file called mysqldump.sql -- -- Table structure for table `Table11` -- DROP TABLE IF EXISTS `Table11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Table11` ( `id` int(11) NOT NULL... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Extracting lines based on identifiers into multiple files respectively

consider the following is the contents of the file cat 11.sql drop procedure if exists hoop1 ; Delimiter $$ CREATE PROCEDURE hoop1(id int) BEGIN END $$ Delimiter ; . . . . drop procedure if exists hoop2; Delimiter $$ CREATE PROCEDURE hoop2(id int) BEGIN END $$ (8 Replies)
Discussion started by: vivek d r
8 Replies

5. Shell Programming and Scripting

Possible to grep string based on surrounding strings?

I was wondering if it was possible to grep a pattern based on the surround text. For example, if i have an input file like this: titleA titleB titlex titleC titleD titlex titleE And I want to grep "title" and save the results only if it is not followed with a "titlex". My output... (14 Replies)
Discussion started by: jl487
14 Replies

6. Shell Programming and Scripting

cut a line into different fields based on identifiers

cat fileanme.txt custom1=, custom2=, userPulseId=3005, accountPolicyId=1, custom3=, custom4=, homeLocationId=0, i need to make the fields appear in next line based on identifier (,) ie comma so output should read cat fileanme.txt custom1=, custom2=, userPulseId=3005, ... (8 Replies)
Discussion started by: vivek d r
8 Replies

7. Shell Programming and Scripting

Remove part of a file based on identifiers

here below is a part of the file cat fileName.txt NAME=APP-VA-va_mediaservices-113009-VA_MS_MEDIA_SERVER_NOT_PRESENT-S FIXED=false DATE= 2013-02-19 03:46:04.4 PRIORITY=HIGH RESOURCE NAME=ccm113 NAME=APP-DS-ds_ha-140020-databaseReplicationFailure-S FIXED=false DATE= 2013-02-19... (4 Replies)
Discussion started by: vivek d r
4 Replies

8. Shell Programming and Scripting

Match part of string in file2 based on column in file1

I have a file containing texts and indexes. I need the text between (and including ) INDEX and number "1" alone in line. I have managed this: awk '/INDEX/,/1$/{if (!/1$/)print}' file1.txt It works for all indexes. And then I have second file with years and indexes per year, one per line... (3 Replies)
Discussion started by: phoebus
3 Replies

9. Shell Programming and Scripting

How to grep the required part from the string?

Hi All, I am trying to fetch the particular content from the result of grep command. I am using ps-ef |grep engine| awk '{print $6}' above statement giving me /opt/test/user/domain/CORPTEST/application/CacheScheduler/CacheScheduler-CacheScheduler but I want (13 Replies)
Discussion started by: sharsour
13 Replies

10. Shell Programming and Scripting

Discard part of a file based on a pattern ---

I have the file: s3_T0(2) Pos "1" "2" s1_T1(2) Pos "1" "2" --- 0 0 1 0 0 1 1 1 --- 1 2 "tau0" 1 2 "h10" I want to patternmatch on --- and get only the third part i.e. 1 2 "tau0" 1 2 "h10" I wanted to start simple but even something like (5 Replies)
Discussion started by: eagle_fly
5 Replies
Net::Jabber::Server(3pm)				User Contributed Perl Documentation				  Net::Jabber::Server(3pm)

NAME
Net::Jabber::Server - Jabber Server Library SYNOPSIS
Net::Jabber::Server is a module that provides a developer easy access to developing applications that need an embedded Jabber server. DESCRIPTION
Server.pm seeks to provide enough high level APIs and automation of the low level APIs that writing and spawning a Jabber Server in Perl is trivial. For those that wish to work with the low level you can do that too, but those functions are covered in the documentation for each module. Net::Jabber::Server provides functions to run a full Jabber server that accepts incoming connections and delivers packets to external Jabber servers. You can use all or none of the functions, there is no requirement. For more information on how the details for how Net::Jabber is written please see the help for Net::Jabber itself. For a full list of high level functions available please see Net::Jabber::Protocol. Basic Functions use Net::Jabber qw(Server); $Server = new Net::Jabber::Server(); $Server->Start(); $Server->Start(jabberxml=>"custom_jabber.xml", hostname=>"foobar.net"); %status = $Server->Process(); %status = $Server->Process(5); $Server->Stop(); METHODS
Basic Functions new(debuglevel=>0|1|2, - creates the Server object. debugfile debugfile=>string, should be set to the path for the debug debugtime=>0|1) log to be written. If set to "stdout" then the debug will go there. debuglevel controls the amount of debug. For more information about the valid setting for debuglevel, debugfile, and debugtime see Net::Jabber::Debug. Start(hostname=>string, - starts the server listening on the proper jaberxml=>string) ports. hostname is a quick way of telling the server the hostname to listen on. jabberxml defines the path to a different jabberd configuration file (default is "./jabber.xml"). Process(integer) - takes the timeout period as an argument. If no timeout is listed then the function blocks until a packet is received. Otherwise it waits that number of seconds and then exits so your program can continue doing useful things. NOTE: This is important for GUIs. You need to leave time to process GUI commands even if you are waiting for packets. The following are the possible return values for each hash entry, and what they mean: 1 - Status ok, data received. 0 - Status ok, no data received. undef - Status not ok, stop processing. IMPORTANT: You need to check the output of every Process. If you get an undef then the connection died and you should behave accordingly. Stop() - stops the server from running and shuts down all sub programs. AUTHOR
By Ryan Eatmon in January of 2001 for http://jabber.org. COPYRIGHT
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2004-08-17 Net::Jabber::Server(3pm)
All times are GMT -4. The time now is 03:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy