Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

How to grep and print portions of a very loooong line of text.?

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-17-2017   -   Original Discussion by newbie_01
newbie_01 newbie_01 is offline
Registered User
 
Join Date: May 2009
Last Activity: 20 November 2017, 7:06 PM EST
Posts: 228
Thanks: 44
Thanked 1 Time in 1 Post
How to grep and print portions of a very loooong line of text.?

Hi,

A bit stumped here trying to grep and wanting to display portion of a text

Using the grep below, I am able to find the line containing the string select


Code:
 ~]$
 ~]$ srvctl -h | grep -i "select"
Usage: srvctl add service -db <db_unique_name> -service <service_name> {-preferred "<preferred_list>" [-available "<available_list>"] [-tafpolicy {BASIC | NONE | PRECONNECT}] | -serverpool <pool_name> [-cardinality {UNIFORM | SINGLETON}] } [-netnum <network_number>] [-role "[PRIMARY][,PHYSICAL_STANDBY][,LOGICAL_STANDBY][,SNAPSHOT_STANDBY]"] [-policy {AUTOMATIC | MANUAL}] [-notification {TRUE|FALSE}] [-dtp {TRUE|FALSE}] [-clbgoal {SHORT|LONG}] [-rlbgoal {NONE|SERVICE_TIME|THROUGHPUT}] [-failovertype {NONE|SESSION|SELECT|TRANSACTION}] [-failovermethod {NONE|BASIC}] [-failoverretry <failover_retries>] [-failoverdelay <failover_delay>] [-edition <edition>] [-pdb <pluggable_database>] [-global {TRUE|FALSE}] [-maxlag <max_lag_time>] [-sql_translation_profile <sql_translation_profile>] [-commit_outcome {TRUE|FALSE}] [-retention <retention>] [-replay_init_time <replay_initiation_time>] [-session_state {STATIC|DYNAMIC}] [-pqservice <pq_service>] [-pqpool <pq_pool_list>] [-gsmflags <gsm_flags>] [-force] [-eval] [-verbose]
Usage: srvctl modify service -db <db_unique_name> -service <service_name> [-serverpool <pool_name>] [-pqservice <pqsvc_name>] [-pqpool <pq_pool_list>] [-cardinality {UNIFORM | SINGLETON}] [-tafpolicy {BASIC|NONE}] [-role [PRIMARY][,PHYSICAL_STANDBY][,LOGICAL_STANDBY][,SNAPSHOT_STANDBY]] [-policy {AUTOMATIC | MANUAL}][-notification {TRUE|FALSE}] [-dtp {TRUE|FALSE}] [-clbgoal {SHORT|LONG}] [-rlbgoal {NONE|SERVICE_TIME|THROUGHPUT}] [-failovertype {NONE|SESSION|SELECT|TRANSACTION}] [-failovermethod {NONE|BASIC}] [-failoverretry <integer>] [-failoverdelay <integer>] [-edition <edition>] [-pdb <pluggable_database>] [-sql_translation_profile <sql_translation_profile>] [-commit_outcome {TRUE|FALSE}] [-retention <retention>] [-replay_init_time <replay_initiation_time>] [-session_state {STATIC|DYNAMIC}] [-maxlag <max_lag_time>] [-gsmflags <gsm_flags>] [-global_override] [-eval] [-verbose] [-force]
 ~]$

Unfortunately, as the line is so, so long and I am actually just interested in the select option and the -e part that precedes it, can someone please advise how to do that.

So ideally, I am hoping to be able to do a grep and it just shows as below. Seriously hoping there is no -select as I don't want to do if it does have a -select, that is if it have -select 1|2|3 Linux


Code:
Usage: srvctl add service ... [-failovertype {NONE|SESSION|SELECT|TRANSACTION}]
Usage: srvctl modify service ... [-failovertype {NONE|SESSION|SELECT|TRANSACTION}]

Any advice much appreciated. Thanks.
Sponsored Links
    #2  
Old Unix and Linux 10-17-2017   -   Original Discussion by newbie_01
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 23 November 2017, 6:28 PM EST
Location: Foxborough, MA
Posts: 8,202
Thanks: 231
Thanked 785 Times in 732 Posts
something along these lines:

Code:
srvctl -h |awk -F '[][]' 'toupper($0)~"SELECT"{for(i=1;i<=NF;i=i+2) if (toupper($(i+1))~"SELECT") print substr($0,1,index($0,"-")-1) "["$(i+1)"]"}'

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Match Strings between two files, print portions of each file together when matched ([g]awk) jvoot UNIX for Beginners Questions & Answers 7 06-29-2017 03:19 AM
Grep echo awk print all output on one line rwalker Shell Programming and Scripting 51 03-28-2016 04:41 AM
Grep in file and print in the line justbow Shell Programming and Scripting 2 10-08-2013 12:02 PM
Grep /Awk letters X - X in every line and print it as a mac address boaz733 UNIX for Dummies Questions & Answers 4 11-15-2011 11:06 AM
Search text from a file and print text and one previous line too kamranjalal Shell Programming and Scripting 6 01-06-2009 03:27 AM



All times are GMT -4. The time now is 07:51 PM.