![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search for words with capital leters | djdaniel3 | Shell Programming and Scripting | 7 | 04-07-2008 02:54 AM |
| Search File for Specific Words | mevasquez | UNIX for Dummies Questions & Answers | 2 | 12-04-2007 04:31 PM |
| Search files that all contain 4 specific words | WoodenSword | Shell Programming and Scripting | 13 | 01-22-2007 06:57 AM |
| Search and replace words between two keywords | vrrajeeb | Shell Programming and Scripting | 6 | 05-11-2005 12:15 PM |
| search for words in file | Agent_Orange | Shell Programming and Scripting | 4 | 10-25-2002 05:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
search two words in sed
I've following sed command working fine -
sed '/search_pattern1/ !s/pattern1/pattern2/" file Now, I want to search two patterns - search_pattern1 and search_pattern2 . How can put these into above sed statement ? Thanks in advance. |
|
||||
|
Do you get a syntax error, or doesn't it do what you expect? Your request can be interpreted at least two ways (lines not containing search_pattern1 or search_pattern2 should have pattern1 replaced with pattern2; or, lines not containing search_pattern1 should have pattern1 replaced with pattern2, and lines not containing search_pattern2 should have some unspecified substitution applied to them) so perhaps you can elaborate with example input, example output, and what exactly you have tried so far.
|
|
||||
|
OK, here is what I want to do
1. I want perform some opreation on the lines which does not have search_pattern1 or search_pattern2. 2. And the operation is - in those lines replace pattern1 by pattern2, if at all pattern1 is present. if pattern1 is not present leave them as it is. In the case where I 've only one search_pattern, The following command works file - sed '/search_pattern1/ !s/pattern1/pattern2/" file Now, I want to add one more word to search "search_pattern2" with "or" condition, I'm not able to fit that into sed. something like - sed '/search_pattern1|search_pattern1/ !s/pattern1/pattern2/" file should work,but it sed treats it like a single word - "search_pattern1|search_pattern1". it does not give a syntaxk error. |
![]() |
| Bookmarks |
| Tags |
| multiple patterns, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|