egrep string except when preceded by underscore


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting egrep string except when preceded by underscore
# 1  
Old 09-30-2009
egrep string except when preceded by underscore

having trouble with this seemingly simple taks.. Smilie

Test data:

Quote:
${DB2HOME}/load_${Gmdsschema}.crnt_rgn_trunc_${SYS_FILE_DATE}
replace into ${Gmdsschema}.crnt_rgn
${Gmdsschema}.crnt_rgn
${DB2HOME}/load_${Gmdsschema}.crnt ${Gmdsschema}.base_rgn
we want to keep lines 2,3 & 4

-- want to exclude when ${.*schema} is preceded with an underscore; Valid {.*schema} should always be preceded spaces or be found at the beginning of a line.



Code:
 
egrep "[^_][$]{.*schema}\."

I would like to thank whomever looks at this in advance for your time .
# 2  
Old 09-30-2009
Code:
egrep '^\${[^}]*schema}|[^_]\${[^}]*schema}'


Last edited by Scrutinizer; 10-01-2009 at 06:57 PM..
# 3  
Old 10-01-2009
or :
Code:
egrep '(^|[^_])\${[^}]*schema}'

# 4  
Old 10-01-2009
Won't this not work for you?
Code:
fgrep '_${' file

# 5  
Old 10-02-2009
Quote:
Originally Posted by edidataguy
Won't this not work for you?
Code:
fgrep '_${' file

Hi editaguy, the OP was trying to match patterns without the preceding underscore. They should also be matched when at the beginning of a line.
# 6  
Old 10-03-2009
Quote:
Originally Posted by Scrutinizer
Hi editaguy, the OP was trying to match patterns without the preceding underscore. They should also be matched when at the beginning of a line.
Oooops....sorry some how I missed it.
Then will this work?
Code:
sed '/_\${.*schema}/ {/ \${.*schema}/!d;}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep how to make sure string is after 5 comma

Hello, Need help... using egrep how do I make sure string is after 5th comma example: a,b,c,d,e,f,g,h,i Suppose i want to search letter f but want to make sure it is after 5th comma. Is there any way to check string is after 5th comma? Thanks !! (9 Replies)
Discussion started by: vegasluxor
9 Replies

2. Shell Programming and Scripting

underscore to dots

Hi, I have been trying to change underscores to dots. For example: 1122_91 1022_233 . 2237_23 9382_2339 2998_234 345_257 . . Desired output: 1122.91 1022.233 . 2237.23 9382.2339 2998.234 345.257 . . Any idea? Thanks (4 Replies)
Discussion started by: iconig
4 Replies

3. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

4. Shell Programming and Scripting

Expect language separating two string connected by _(underscore)

Hi Folks, Anybody has an idea how to split string based on separator _ (underscore) in Expect programming language? e.g.if string is scmid1_scmid2 , i need to separate these two strings as scmid1 and scmid2. Thanks in advance. Sanket (1 Reply)
Discussion started by: Sanket
1 Replies

5. UNIX for Advanced & Expert Users

google search changes with an underscore

How does adding an underscore change a google search? I was searching for John Elway and got different results with and without an unscore. (3 Replies)
Discussion started by: cokedude
3 Replies

6. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

7. Shell Programming and Scripting

allow only alphnumeric entry and an underscore

I am taking an user input which should only be an alphanumeric character or an underscore. How to i do it? (2 Replies)
Discussion started by: vickylife
2 Replies

8. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

9. UNIX for Dummies Questions & Answers

problem with underscore in variable name

can you help please. variable 1 = TODAY=`date +"%Y%m%d"` i.e. echo $TODAY 20080407 DB=GERMANY echo $DB GERMANY echo $DB.$TODAY GERMANY.20080407 echo $DB.$TODAY_1.dmp GERMANY..dmp (3 Replies)
Discussion started by: pinkie
3 Replies

10. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies
Login or Register to Ask a Question