Home Man
Search
Today's Posts
Register

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
# 1  
Old 10-17-2017
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

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

Any advice much appreciated. Thanks.
# 2  
Old 10-17-2017
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)"]"}'

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
Find line then evaluate text on next line, print when condition is met LMHmedchem Shell Programming and Scripting 5 02-07-2018 02:47 PM
Match Fields between two files, print portions of each file together when matched in ([g]awk)' jvoot UNIX for Beginners Questions & Answers 2 01-05-2018 02:12 PM
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
Use less pipe for grep or awk sed to print the line not include xx yy zz yanglei_fage Shell Programming and Scripting 3 11-23-2013 02:37 PM
Grep in file and print in the line justbow Shell Programming and Scripting 2 10-08-2013 11:02 AM
grep a string and print strings on that line kingpeejay Shell Programming and Scripting 4 11-30-2010 02:57 PM
grep N lines after match and then print them on 1 line each alekkz UNIX for Dummies Questions & Answers 10 09-28-2009 12:33 PM
grep N lines after match and then print them on 1 line each alekkz Shell Programming and Scripting 1 09-26-2009 05:16 PM
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 08:12 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password