OT: Linux Shell Script

From: Tyson Scott <tscott_at_ipexpert.com>
Date: Wed, 28 Apr 2010 00:19:49 -0400

Hey guys,

 

Ignore this if you are not familiar with Linux. I am throwing this out
because I expected it to work and can't get it working.

 

I am trying to create a bash script to delete two lines in a file only if
they are directly connected to one another.

 

For example if I had a file "file.txt" with the following lines

1

2

3

4

5

 

And I wanted to delete the lines with 3 & 4 but only if they were together.
i.e. I want to make sure I am not deleting if they are:

1

3

2

4

5

 

I know I could do

sed '/3/d' -i file.txt;sed '/4/d' -i file.txt

 

but that doesn't make sure they are directly together

 

I tried

 

sed '/3$\r\n4/d' -i file.txt

 

But it seems either it doesn't match or I am using the incorrect regular
expression

 

I know I could also do

 

cat file.txt | grep -v 3 | grep -v 4 > file.txt

 

but still not making sure it is one line. Any thoughts would be
appreciated. I believe there should be a way to do this with sed but I
wouldn't call myself a guru on the great intricacies of sed. If not then I
will just use expect, but I wanted to keep it simplistic.

 

I know with expect I can do

expect -re "\n3\r\n4" { exec sed '/3/d' -i file.txt;sed '/4/d' -i file.txt }

 

And that verifies the two lines are together and then I can delete the files
based off of them being together but I was hoping to stick with a simple
bash shell script for this task.

 

Regards,

 

Tyson Scott - CCIE #13513 R&S, Security, and SP

Technical Instructor - IPexpert, Inc.

Mailto: tscott_at_ipexpert.com

Telephone: +1.810.326.1444, ext. 208

Live Assistance, Please visit: www.ipexpert.com/chat

eFax: +1.810.454.0130

 

IPexpert is a premier provider of Self-Study Workbooks, Video on Demand,
Audio Tools, Online Hardware Rental and Classroom Training for the Cisco
CCIE (R&S, Voice, Security & Service Provider) certification(s) with
training locations throughout the United States, Europe, South Asia and
Australia. Be sure to visit our online communities at
www.ipexpert.com/communities and our public website at www.ipexpert.com
<http://www.ipexpert.com/>

Blogs and organic groups at http://www.ccie.net
Received on Wed Apr 28 2010 - 00:19:49 ART

This archive was generated by hypermail 2.2.0 : Sat May 01 2010 - 09:49:57 ART