The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK: Multiple patterns per line Plavixo UNIX for Dummies Questions & Answers 1 05-05-2008 04:31 PM
Perl: Match a line with multiple search patterns Juha Shell Programming and Scripting 10 04-09-2008 01:43 AM
3 patterns in one line bashuser UNIX for Advanced & Expert Users 1 02-16-2008 07:02 PM
Searching for data on a specific line numbers rkumar28 Shell Programming and Scripting 8 06-18-2005 12:34 AM
Append a field to the end of each line of a file based on searching another file. ultimate Shell Programming and Scripting 2 03-29-2005 10:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-04-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
searching for two or more patterns in a line

how can I search for two or more patterns in one line using grep?
for example if I want to show only the lines that have patterns "abc" and "123"?
and what if I want to show only the lines that have either "abc" or "123" in them?
any hint apprecited
  #2 (permalink)  
Old 02-04-2008
pt14 pt14 is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 28
egrep "pattern1|pattern2" filename
  #3 (permalink)  
Old 02-04-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
tnx but that doesnt work in grep.
but worked well with egrep.
  #4 (permalink)  
Old 02-04-2008
metalwarrior metalwarrior is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 16
sed (assigning two or more patterns) ?

hi, how does regular expression for "or" and "and" work in sed?
like if I want sed to find and do something only with the lines that contain "abc" or "123" pattern. or lines that have "abc" and "123" both.
I normally use this regular expression for that: ."*{abc,123}.*" but itdoesnt work in sed.
can anyone fix this line for me?
sed '.*{abc,123}.*/s# etc...' filename
  #5 (permalink)  
Old 02-05-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
showing lines that contain abc and 123 both (using Perl):
Code:
perl -nl -e 'print if (m/abc/  and  m/123/);' file
Sponsored Links
Closed Thread

Bookmarks

Tags
egrep, perl regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0