Egrep command is not working for me

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Egrep command is not working for me
# 1  
Old 07-16-2017
Egrep command is not working for me

my file is below
Code:
REREGISTER is something to Failed to create the request
Failed to create the request in not easy
I know how REREGISTER

command i run is
egrep 'REREGISTER|Failed|to|create|the|request' test1

expected output
Code:
REREGISTER is something to Failed to create the request

i should get only first line as output but i am getting all the line.please advise what is wrong i am doing

Last edited by mirwasim; 07-16-2017 at 01:45 PM..
# 2  
Old 07-16-2017
One way.

Code:
grep 'REREGISTER' test1 | grep 'something'

A much more advanced way is to use negative lookahead.

Suppose you want to eliminate lines with the word "bar" in them:
Code:
egrep '^(?!.*bar).*$'  filename

I'm not sure which one would be best, but the first one is easier to apply to your example. If you have a large number of lines then it becomes much harder to get a clean answer to what you should do.

BTW - your original syntax says any one of the following words ( in your pipe delimited section) is a match print it.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 07-16-2017
Hello mirwasim,

It is showing like that output because you are giving an OR condition which means any of these words if they are coming into a line then print it(so that is why other than 1st lines are getting printed too because any of the words are coming there), if words sequence will be same as per shown sample Input_file then following may help you in same.
Code:
egrep 'REREGISTER.*Failed.*to.*create.*the.*request'    Input_file

Thanks,
R. Singh
These 2 Users Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep not working with -f option

Hi, I am trying to find out patterns in file 1 using patterns stored in file 2. Following is the code FILE1=inputfilename FILE2=blacklist blacklist 1203 97715555 20afEOF egrep -f $FILE2 $FILE1 but the above code is not working either using egrep or grep. Just for your... (10 Replies)
Discussion started by: siramitsharma
10 Replies

2. Shell Programming and Scripting

help in egrep command in file

Hi Guys, I need hepl on egrep commnad I have one file and i need grep only specific lines.. EX: 2012-04-01 02:15:14 w 2012-04-01 02:15:14 w 2012-04-01 02:15:14 w 2012-10-26 02:15:14 w 2012-04-01 02:15:14 w 2012-10-26 02:15:14 w 2012-10-26 02:15:14 w 2012-10-26 03:18:56 M... (1 Reply)
Discussion started by: asavaliya
1 Replies

3. Shell Programming and Scripting

Help with egrep command

Hello folks, Here's how my current egrep command works: egrep "NY|DC|LA|VA|MD" state_data.txt I am planning to use a file to enter all allowable state values like say a new state_names.lookup with the following data: NY DC LA VA MD egrep "`cat state_names.lookup`"... (6 Replies)
Discussion started by: calredd
6 Replies

4. Shell Programming and Scripting

Help with egrep command

cat /tmp/inventory.csv|grep AARP|egrep -v "T11|12.4\(7\)" how do i exclude in addition to above 12.4\(3\) I have tried adding this in i.e -v "T11|12.4\(7\)|12.4\(3\)" but it did not work (3 Replies)
Discussion started by: slashbash
3 Replies

5. Shell Programming and Scripting

matching a regex using egrep not working

Hi, I'm trying to validate if a string matches a regular expression, but it is not working. Am I missing something? Do I need to scape any of the characters? if echo 'en-GB' | egrep '({1,8})(-{1,8})*' >/dev/null; then echo Valid value fi Thanks in advance (6 Replies)
Discussion started by: skrtxao
6 Replies

6. Shell Programming and Scripting

egrep command and order

Hi All, Here is my question. I have two files, file1.txt and file2.txt. I need the line number (index number) of file2.txt where the words in file1.txt appear. But they have to be in the same order as file1.txt. In example, file1.txt Z K A ... T file2.txt W A Q R (6 Replies)
Discussion started by: senayasma
6 Replies

7. Shell Programming and Scripting

Query regarding egrep command

Hi All, I am having a query regarding the usage of egrep command. i am having two unix environmanets in environment when i am using "egrep -f" it is working fine and other unix environment i am getting a syntax error. Please let me know if i need to set any environmane variables. ... (12 Replies)
Discussion started by: Sriram.Vedula53
12 Replies

8. Shell Programming and Scripting

Help with egrep command

Hi All, I am using egrep command to search one pattern. Following is the command i am using egrep -i "ACL*" filename but its also giving me the records which do not contain ACL. any help would be appreciated. Regards, Sam (3 Replies)
Discussion started by: sam25
3 Replies

9. Shell Programming and Scripting

egrep command

I'd like to grep a pattern of a version number as *_number.number.number number should be digit my grep is |egrep '^*++\.+' It works for V_3.2.1 or V _5.3.2 but not with V_43.6.543 !!!!! How can I specify any repetition of digit in the ? thanks, (4 Replies)
Discussion started by: annelisa
4 Replies

10. UNIX for Dummies Questions & Answers

egrep -e not working...!

:cool: fedora core 2 version 2.6.8-1.521 gnu/linux the last version of redhat that I was working with linux 8.0 a special version that came with a book.. on this version and on spider tools linux 0.9 the second version I worked with.. when i envoked egrep -e from file1 to file2 I would get the... (4 Replies)
Discussion started by: moxxx68
4 Replies
Login or Register to Ask a Question