Help identify string using sed

I have the following output and would like to only identify strings with "vw" at the end.

Here is the file contents:

SELECT n.contract_num, n.descr, s.prj_level2_cf_val, r.descr, r.project_id,
p.offering_id, o.n_cust_contract, u.name1, ' ', ' ', SUM (0),
TO_CHAR (t.start_dt, 'YYYY-MM-DD'), TO_CHAR (t.end_dt, 'YYYY-MM-DD'),
o.n_contract_cat, o.n_contract_subcat, o.n_gsa_contract,
o.n_subcontract, n.business_unit
FROM ps_ca_contr_hdr n,
ps_n_ca_ctr_hdr_vw n1,
ps_n_ca_header o,
ps_ca_detail p,
ps_ca_detail_proj q,
ps_project r,
ps_sp_bu_pc_clsvw r1,
ps_psa_orgprj_defn s,
ps_project_status t,
ps_customer u
WHERE n.contract_num = n1.contract_num
AND n1.oprclass = 'DRC_RL_PL_DRC'
AND o.contract_num = n1.contract_num
AND r.business_unit = r1.business_unit
AND r1.oprclass = 'DRC_RL_PL_DRC'
AND s.business_unit = r1.business_unit
AND t.business_unit = r1.business_unit
AND ( n.contract_num = o.contract_num
AND o.contract_num = p.contract_num
AND p.contract_num = q.contract_num
AND p.contract_line_num = q.contract_line_num
AND q.project_id = r.project_id
AND q.project_id = s.project_id

Here is what I use to extract my strings:

sed -n 's/.*\([Pp][Ss]_.*\) .*/\1/p' x.x | sort | uniq

to get the following output:

ps_ca_contr_hdr
ps_ca_detail
ps_ca_detail_proj
ps_customer
ps_n_ca_ctr_hdr_vw
ps_n_ca_header
ps_n_nodedptlst_vw
ps_nvs_scope_field
ps_nvs_scope_value
ps_pc_res_fund
ps_proj_funding
ps_project
ps_project_status
ps_psa_orgprj_defn
ps_sp_bu_pc_clsvw

How do I limit my string return to only strings ending in "vw" or "_vw" with the sed command ????

[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]

try grep.

sed -n 's/.*\([Pp][Ss]_.*\) .*/\1/p' x.x | sort -u | grep "vw$"

or the following, pardon my lack of sed knowledge as this might not be correct but worked on my test system.

sed -n 's/.*\([Pp][Ss]_.*[Vv][Ww]\) .*/\1/p' x.x | sort -u
1 Like

what is your desired output?

You could also specify a pattern before the sed edit command, e.g.

sed -n '/vw$/ s/.*\([Pp][Ss]_.*\) .*/\1/p' x.x | sort | uniq

not sure to understand your need...

sed '/vw/!d;s/ [^ ]*$//' x.x
ps_n_ca_ctr_hdr_vw
ps_sp_bu_pc_clsvw

?

grep -io 'ps[^ ]*vw' infile | sort

Thanks UNXSCOROB. That works perfectly