Help identify string using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help identify string using sed
# 1  
Old 10-06-2011
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:
Code:
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:
Code:
sed -n 's/.*\([Pp][Ss]_.*\) .*/\1/p' x.x | sort | uniq


to get the following output:
Code:
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 ????



Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 10-06-2011 at 11:26 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-06-2011
try grep.
Code:
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.
Code:
sed -n 's/.*\([Pp][Ss]_.*[Vv][Ww]\) .*/\1/p' x.x | sort -u


Last edited by unxscorob; 10-06-2011 at 11:09 AM.. Reason: adding more content
This User Gave Thanks to unxscorob For This Post:
# 3  
Old 10-06-2011
what is your desired output?
# 4  
Old 10-06-2011
You could also specify a pattern before the sed edit command, e.g.
Code:
sed -n '/vw$/ s/.*\([Pp][Ss]_.*\) .*/\1/p' x.x | sort | uniq

# 5  
Old 10-06-2011
not sure to understand your need...

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

?
# 6  
Old 10-06-2011
Code:
grep -io 'ps[^ ]*vw' infile | sort


Last edited by Scrutinizer; 10-06-2011 at 12:45 PM..
# 7  
Old 10-06-2011
Thanks UNXSCOROB. That works perfectly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to identify delimiter to find and replace a string with sed?

I need to find and replace a date format in a SQL script with sed. The original lines are like this: ep.begin_date, ep.end_date, ep.facility_code, AND ep.begin_date <= '01-JUL-2019' ep.begin_date, ep.end_date, ep.facility_code, AND ... (15 Replies)
Discussion started by: duke0001
15 Replies

2. Shell Programming and Scripting

How to identify exact text and then add a blank line above it using sed?

I need to identify the exact text of San Antonio Generator Running in the output my script which lands to a text file. Once SED finds the specific text, I need it to insert one line above the matched text. Here is what I have so far that isn't working all that well for me. Any help would be... (7 Replies)
Discussion started by: jbrass
7 Replies

3. UNIX for Advanced & Expert Users

How to identify particular section using sed?

Hi, I have following data in a file. Not all but most of the lines start with letter 'T' has 8 SPACES from column 121 to 128 and I want to replace that portion with some dummy value. Is it possible through sed? Input File:- T1111111111111A 20140310000000005076358416369283 AAAAA ... (6 Replies)
Discussion started by: jnrohit2k
6 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. UNIX for Dummies Questions & Answers

Use Regex to identify / format a complex string

First of all, please have mercy on me. I am not a noob to programming, but I am about as noob as you can get with regex. That being said, I have a problem. I've got a string that looks something like this: Publication - Bob M. Jones, Tony X. Stark, and Fred D. Man, \"Really Awesome Article... (1 Reply)
Discussion started by: egill
1 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. HP-UX

Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (1 Reply)
Discussion started by: kk2202
1 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

Shell Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (2 Replies)
Discussion started by: kk2202
2 Replies

10. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies
Login or Register to Ask a Question