![]() |
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 |
| 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 |
| regular expression help pls | miwinter | UNIX for Dummies Questions & Answers | 3 | 06-05-2008 01:14 AM |
| Regular expression | maxvirrozeito | UNIX for Dummies Questions & Answers | 1 | 12-14-2007 08:02 AM |
| regular expression and awk | nickg | UNIX for Dummies Questions & Answers | 2 | 08-16-2007 05:23 PM |
| regular expression..help!! | andy2000 | UNIX for Dummies Questions & Answers | 1 | 07-25-2007 03:31 PM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Regular Expression - Replace if x contains y except if...
Hi all,
I have a file which contains 1000s of lines of text. I need to delete all lines with the words "Red" EXCEPT if the line also contains the word "GREEN"... For example: ThisIs some random text that should be red deleted ThisIs some random text that should NOT be red deleted green In this case the first line should be deleted totally BUT the second line should remain in the file...Any suggestions on this would be appreciated, |
|
||||
|
There is probably a more efficient way to di this...
Code:
while read line
do
echo $line | grep -i red > /dev/null
if [ $? -eq 0 ]
then
echo $line | grep -i green > /dev/null
if [ $? -eq 0 ]
then
echo $line >> new_file
fi
else
echo $line >> new_file
fi
done < input_file
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|