problems egreging for a '(0)' string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problems egreging for a '(0)' string
# 1  
Old 02-03-2006
problems egreging for a '(0)' string

Hi,

I'm trying to egreg for a couple strings whcih are (0) and SYSTEM. The problem is the syntax for egreg is:

egreg "(string1|string2)"

With my basic knowledge of UNIX I don't know how to include '(0)' within "(string1|string2)" apart from trying to use single quotes which doesn't work, i.e. "('(0)')".

I reckon this must be eary to resolve but need some expert advice.

Can anyone help?

Gareth
# 2  
Old 02-03-2006
why dont u try as such,

Code:
egrep '(0)|system' filename

# 3  
Old 02-03-2006
Thanks, I've tried this and it doesn't work. This provides the same output as:

egrep -v "0|SYSTEM"
# 4  
Old 02-03-2006
i dont understand,

can u plz post the sample input and output.
# 5  
Old 02-03-2006
Madhan's command works absolutly fine.. here is how it works

$ more tmp1
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file

$ egrep '(0)|SYSTEM' tmp1
this is test (0) for unix.com
also to test SYSTEM for the same

can you tell me what was the error you got ?
# 6  
Old 02-03-2006
I don't know if egrep works the same everywhere, but: why not use grep instead?

grep -e "0" -e "SYSTEM"

will find every line containing either "0" or "SYSTEM" - at least on my AIX system.

bakunin
# 7  
Old 02-03-2006
Quote:
Originally Posted by mahendramahendr
Madhan's command works absolutly fine.. here is how it works

$ more tmp1
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file

$ egrep '(0)|SYSTEM' tmp1
this is test (0) for unix.com
also to test SYSTEM for the same

can you tell me what was the error you got ?
Whilst you're seeing what you think is the correct output that's because it's actually greping for 0 and SYSTEM

# cat tmp
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file
this is test 0 for unix.com

If I want to exclude lines including (0) using your syntax I get the following result:

# egrep -v '(0)|SYSTEM' tmp
hai it is the begining
this is the end of the file

Line 5 should not have been removed if the pattern is (0)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

2. Shell Programming and Scripting

Problems with Multiple Pattern String Matching

I am facing a problem and I would be grateful if you can help me :wall: I have a list of words like And I have a datafile like the box of the box of tissues out of of tissues out of the book, the the book, the pen and the the pen and the I want to find Patterns of “x.*x” where... (2 Replies)
Discussion started by: A-V
2 Replies

3. Shell Programming and Scripting

String comparison problems

Req: =========== 1)I have one shell script a.sh 2)I opened Putty session , with user name = SIR100 , and i ran a.sh script in back ground and it took 5 minutes to complete.Meanwhile,i ran same script second time i.e a.sh with same user it sholud not allow to run the script , but it's... (3 Replies)
Discussion started by: as234301
3 Replies

4. Shell Programming and Scripting

Problems assigning a string to a variable

Hello everyone, My problem looks quite simple , how to assign a string with spaces and lines "\n" to a variable. I've tried all kind of quoting and is impossible, bash always try to execute the string and never executes a simple assignation. This is part of the code ... (1 Reply)
Discussion started by: trutoman
1 Replies

5. Shell Programming and Scripting

SED delete string from till problems

Hi i have a file which contains 2 lines, line 1 is static data. line 2 is a very large string(over 3000char or much more). in that string are tags which i want to delete. e.g. <order1>123</order1><tag1>data</tag1><new>1</new><order2>124</order2><tag1>data</tag1> all one one line. now i... (5 Replies)
Discussion started by: subby80
5 Replies

6. Shell Programming and Scripting

String concatenation problems

#! /bin/csh set tt=12345_UMR_BH452_3_2.txt set rr=`echo $tt | cut -d_ -f1` set rr1=welcome set ff=$rr $rr1 echo $ff why $ff returned only 12345 and not 12345welcome? thanks (2 Replies)
Discussion started by: jdsignature88
2 Replies

7. Shell Programming and Scripting

problems getting a segment from a string output

Hi I'm creating a script that creates files from svn checkout and compress them using tar.gz the script gets the repository name from command line argument i need to capture a number from the last line of the output and create a file name from it. the svn returns output of all the file... (5 Replies)
Discussion started by: tzvio
5 Replies

8. Shell Programming and Scripting

awk: split a file using a string problems

Hi, if i use this code awk '/String/{n++}{print > f n}' f=file input I get "input" splited this way file1 String 1515 1354 2356 file 2 String 4531 0345 5345 (3 Replies)
Discussion started by: aloctavodia
3 Replies

9. Shell Programming and Scripting

find: problems escaping printf-command string

Hi Folks! Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused: My shell script snippet looks like this: #!/bin/sh .. COMMAND="find ./* -printf '%p %m %s %u %g \n'" echo "Command: ${COMMAND}"... (1 Reply)
Discussion started by: grahamb
1 Replies

10. Shell Programming and Scripting

variable= 'cat file|wc -l' String problems

Hi, does anybody knows about wc -l, how to transform it inot a just number? this script ALWAYS executes the command3!!, However, the value of BMU_RUNNING is 1 case $BMU_RUNNING in *0) command1 ;; *1) command 2;; *)command 3;; esac The... (3 Replies)
Discussion started by: Santiago
3 Replies
Login or Register to Ask a Question