Weird requirement using egrep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird requirement using egrep
# 1  
Old 07-21-2011
Weird requirement using egrep

Hi,

I have a weird requirement using egrep.
I'm using egrep -o 'x.*|y.*' to a file.
Since egrep returns the value if either of the 1 satisfies.
But in my file both the conditions are satisfied (x and y) and hence I want to return twice using this command.
Is there any way around?
I don't want to use looping and all.
I would prefer single egrep solution.

Thanks
# 2  
Old 07-21-2011
give sample file contents
# 3  
Old 07-21-2011
egrep requirement sample example

Lets say content of file has only 1 line

ABCDE (x,y,z,abc)

if you use egrep -o x.* content will be "x,y,z,abc)"
if you use egrep -o y.* content will be "y,z,abc)"
But if you use egrep -o 'x.*|y.*' I'm getting "x,y,z,abc)"
I want both.
This has impacted my output
# 4  
Old 07-21-2011
Is there any option like egrep -o ???
Just check the man pages

You are working on which OS

infile
Code:
ABCDE (x,y,z,abc)

Code:
egrep y.* infile

If you give above code it will give you entire line in the output

output
Code:
ABCDE (x,y,z,abc)


Cheers
Harish

Last edited by harish612; 07-21-2011 at 01:39 AM..
# 5  
Old 07-21-2011
I'm working on Linux and yes egrep -o option works
# 6  
Old 07-21-2011
I believe it's impossible with grep. As far as I know grep prints a result as quick as possible and goes to the next line.
But it's easy with sed (or, for example, perl).
# 7  
Old 07-21-2011
give me the sed command pls.
This will also help
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX requirement

Hi Everyone, Can anyone of you help me on how to get files creation time on ftp server/Remote server in unix. Regards, Avinash. (6 Replies)
Discussion started by: Avinash varma
6 Replies

2. Shell Programming and Scripting

UNIX - requirement

Hi All, I have a source file with data Name ~ Groups Muni~abc,was,USA_ax,123 Chaitanya~USA_12,was Balaji~123,xyz,was Ramu~123,xyz From the second column i want to extract only the groups that matches the pattern 'USA_%' or if the group = 'was', and ignore any other columns. ... (8 Replies)
Discussion started by: morbid_angel
8 Replies

3. Shell Programming and Scripting

Looping requirement

Hi all, I have little working knowledge in unix shell scripting. I have a requirement where i need to pull out some data in between the strings in the file. Input: TEST a a c f d TEST f e g g TEST Output: (7 Replies)
Discussion started by: satyasrin82
7 Replies

4. Shell Programming and Scripting

URGENT REQUIREMENT

1.Write an automated shell program(s) that can create, monitor the log files and report the issues for matching pattern. (i) Conditions for creating log files. Log file is created with date (example 2010_03_27.log). If the log file size is 10 Mb for a particular day then automatically the log... (3 Replies)
Discussion started by: praveen12
3 Replies

5. Shell Programming and Scripting

Requirement

I am trying to script and came up with a conclusion that I need a do while loop in my statement. I am stuck with the do while syntax. I need to use it alongwith the if then else statement. Can I use it is a big question? I actually need to get all the files that are there from within run_dt to... (1 Reply)
Discussion started by: aronmelon
1 Replies

6. AIX

SPOT requirement

Hey May be a dumb question Can I use a SPOT which is at 5.3 TL6 to boot an LPAR (with 5.3 TL8) in to maintenance mode? Will it work ? Is it mandatory that SPOT should be of same or higher version in such case? Bala (1 Reply)
Discussion started by: balaji_prk
1 Replies

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

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