Egrep help needed?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Egrep help needed?
# 1  
Old 12-26-2012
Egrep help needed?

Can anyone advise how to use grep to locate lines containing these patterns?
i) SIGSTOP or SIGTSIP
ii) SIGTTIN or SIGTTOU
iii) harris or harrison

Say the file contents are
$ cat reg_exp
SIGSTOP
SIGTSIP
SIGTTIN
SIGTTOU
harris
harrison


I tried using, but did not worked
$ grep -E 'SIG[STOP|TSIP]' reg_exp
SIGSTOP
SIGTSIP
SIGTTIN
SIGTTOU


Thanks in advance,
# 2  
Old 12-26-2012
Code:
grep  "^[SIG]\{3\}\(STOP\|TSIP\)" reg_exp

OR
Code:
grep  "^SIG\(STOP\|TSIP\)" reg_exp

# 3  
Old 12-26-2012
Could you please advise why you have used \ in following?
Code:
grep  "^SIG\(STOP\|TSIP\)" reg_exp

Thanks in advance,

---------- Post updated at 11:30 AM ---------- Previous update was at 11:24 AM ----------

Tried using -E and it worked...
$ grep -E 'harris(|on)' reg_exp
harris
harrison
# 4  
Old 12-26-2012
From grep manual page:

In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the back-slashed versions \?, \+, \{, \|, \(, and \).
# 5  
Old 12-26-2012
Also used egrep for other pattern:

$ grep -E 'SIG(STOP|TSIP)' reg_exp
SIGSTOP
SIGTSIP
# 6  
Old 12-26-2012
Yes.

-E option interprets PATTERN as an extended regular expression. So you don't have to use the back-slashed versions. Since I did not use this option I had to use back-slashed versions.

I hope you understood.

Last edited by Yoda; 12-26-2012 at 02:12 AM.. Reason: fixed typo
# 7  
Old 12-26-2012
Yes, I am clear.

Thanks for you help and time Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed with egrep

Hello folks, I am having an issue with searching for a pattern using egrep (or grep). For ex, in the below file. I am searching for all files with a particular pattern but I am not able to figure out what the issue is? $ cat test.dat TEST_211815.TXT TEST_111915.TXT TEST_112015.TXT... (2 Replies)
Discussion started by: calredd
2 Replies

2. Shell Programming and Scripting

Egrep

Hi I am trying to run CMD that combining EGREP and PERL in multiple files cat *07:00.22-12-13.txt | egrep" NAME| perl -ne 'print if /^sid9/ .. /^!/' " I need the see the NAME and the text from sid9 to ! how can I use the EGERP in parallel to the PERL ? This is one file Qqq... (2 Replies)
Discussion started by: sharong
2 Replies

3. Shell Programming and Scripting

Using egrep.

I have a text file which has the content starting with "....." Not able to filter out lines staring with "....." Is there anything wrong with grep stagement ?? .....processing table 2 of 2 .....migration process started at 2012-10-04 05:00:28 .....estimated # of rows 169,830... (2 Replies)
Discussion started by: Nagaraja Akkiva
2 Replies

4. Shell Programming and Scripting

Egrep help needed

What does the below statement mean? 1. egrep -m 1 -cif "ignore_list" "file" 2. egrep -vif "ignore_list" "file" Thanks in Advance Robin. (1 Reply)
Discussion started by: robinbannis
1 Replies

5. UNIX for Dummies Questions & Answers

help on egrep

HI, I have two files filea, fileeb filea z283110z67 xx65686377 xx654681zz xx652836xx xx653881zz xx65480z11 xx654z5466 xx65510000 xx65670000 xx656z0000 xx656z1822 fileb (3 Replies)
Discussion started by: krao
3 Replies

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

7. Shell Programming and Scripting

egrep help

Hi there, Im having some issues using egrep, I have a text file containing server logs: the user imputs 2 arguments, which are error checked and made into $searchMonth $searchYear respectivley. I then do the grep command: egrep /$searchMonth/ $file | egrep /$searchYear: | wc -l ... (1 Reply)
Discussion started by: Darklight
1 Replies

8. Shell Programming and Scripting

egrep

Hi, I don't understand what is the correct way of writing: egrep -l '{$min,$max} $pattern' $filename I tryed to search on google how to wtrite {$min, $max}, but I don't have success (7 Replies)
Discussion started by: DNAx86
7 Replies

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

10. UNIX for Dummies Questions & Answers

egrep -f

Hi, i am using egrep -f. The file with the expressions is very big and if i make the file a lot smaller, it works fine. Only if i use the original file, witch has about 20.000 lines it doesn't seem to work. Is the file to big, or do i need more patience?? my command is: egrep -f... (2 Replies)
Discussion started by: tine
2 Replies
Login or Register to Ask a Question