Show Password


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.?

👤 Login to reply
Thread Tools Search this Thread Display Modes
Old 10-17-2017
newbie_01 newbie_01 is offline
Registered User
Join Date: May 2009
Last Activity: 22 May 2018, 8:32 PM EDT
Posts: 236
Thanks: 45
Thanked 1 Time in 1 Post
How to grep and print portions of a very loooong line of text.?


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

 ~]$ 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

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
Old 10-17-2017
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
Join Date: Feb 2005
Last Activity: 17 July 2018, 3:20 PM EDT
Location: Foxborough, MA
Posts: 8,310
Thanks: 257
Thanked 838 Times in 782 Posts
something along these lines:
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
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:19 AM
Grep echo awk print all output on one line rwalker Shell Programming and Scripting 51 03-28-2016 03:41 AM
Grep in file and print in the line justbow Shell Programming and Scripting 2 10-08-2013 11:02 AM
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 10:06 AM
Search text from a file and print text and one previous line too kamranjalal Shell Programming and Scripting 6 01-06-2009 02:27 AM

All times are GMT -4. The time now is 03:25 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.