Explanation on egrep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Explanation on egrep
# 1  
Old 01-30-2012
Explanation on egrep

Hi all

I am new to egrep can someone please explain me what does the below Statement do
Code:
 egrep -v "^missing sales|^\[Sales_Update"

Thanks in advance
Sri

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 02-01-2012 at 07:02 AM..
# 2  
Old 01-30-2012
Code:
$ egrep -v "^missing sales|^\[Sales_Update" test.txt                                                                                               
abcd
efghg

$ cat test.txt
missing sales
[Sales_Update
abcd
efghg

# 3  
Old 01-30-2012
egrep => Extended grep, same as grep -E. Check man grep to see what extra features are supported by egrep.
-v => This switch will enable grep to print all those lines that doesn't match the pattern.
"^missing sales|^\[Sales_Update" => If string starts with "missing sales" or "[Sales_Update"

To summarise: If any line from input file (or stdin) starts with "missing sales" or "[Sales_Update", skip those lines and print the rest.
# 4  
Old 02-01-2012
Hi

What is the use of '/' then in other words what will happen if we dont give that

Sri
# 5  
Old 02-01-2012
Reqular expressions use the square brackets to indicate a character range, the backslash \ is used to escape the following character, thus preventing the regex engine from interpreting it as the beginning of a range.

If it is not included the grep will fail with an error similar to grep: Unmatched [ or [^.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Explanation around "+r" in egrep

Hi, Is anyone able to shed some light on "+r"? I know -r in grep refers to a recursive search - I am curious to know what +r specifies. #show process pidin | utility egrep -e "+r" count 2492 Thanks. (3 Replies)
Discussion started by: sand1234
3 Replies

2. Shell Programming and Scripting

Need explanation

Hi, I need more explination on it, how it works abcd="$(echo "$abcd" | sed 's/ //g')" >> ${LOGFILE} 2>&1 can any one suggest me on this? Rgds, LKR (1 Reply)
Discussion started by: lakshmanraok
1 Replies

3. Shell Programming and Scripting

code explanation

Can you please explain the following code plz? my_cd=' ' while getopts :e: OPTION; do case "$OPTION" in e) my_cd ="$OPTARG";; esac done if ; then echo " >>> ERROR - I am wrong" echo " >>> ERROR - Hello" exit 99 fi What I don't understand is what is OPTION or... (3 Replies)
Discussion started by: RubinPat
3 Replies

4. UNIX for Dummies Questions & Answers

In need of explanation

Its great someone provided this script that strips out a filename and extension but can someone explain how each line works? file1='Jane Mid Doe.txt' newfile='Jane.txt' 1) ext=${file1##*.} 2) filename=${file%%.???} 3) set -- $filename 4) newfile="1.$extension" (1 Reply)
Discussion started by: Lillyt
1 Replies

5. Shell Programming and Scripting

same action in then as in else: explanation?

in /etc/init.d/networking of an ubuntu computer, I found this code: if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi Shouldn't it be replace by ifdown -a --exclude=lo ... (0 Replies)
Discussion started by: raphinou
0 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. 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

8. UNIX and Linux Applications

need explanation

Hi am having a c pgm. It has the include files (unistd.h,sys/types.h,win.h,scr.h,curses.h,stdarg.h and color.h). I don't know the purpose of these include files. will u plz explain me. (1 Reply)
Discussion started by: Mari.kb
1 Replies

9. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (1 Reply)
Discussion started by: convenientstore
1 Replies

10. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (0 Replies)
Discussion started by: convenientstore
0 Replies
Login or Register to Ask a Question

Featured Tech Videos