Thanks for responding with this Carlos. I think I am going to take another
linux shell scripting class so I can become more proficient with the power
of the bash ;).
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
-----Original Message-----
From: Carlos G Mendioroz [mailto:tron_at_huapi.ba.ar]
Sent: Wednesday, April 28, 2010 7:21 AM
To: Tyson Scott
Cc: ccielab_at_groupstudy.com
Subject: Re: OT: Linux Shell Script
Hey Scott,
the problem is that sed/grep are line tools, so multiline is ...
complicated.
There is a nice post at
http://ilfilosofo.com/blog/2008/04/26/sed-multi-line-search-and-replace/
on how to load sed's hold buffer with the whole input and then do
in memory edits, which can be multiline.
In your case,
sed -n '1h;1!H;${;g;s/3[^\n]*\n4[^\n]*\n//;p;}' file.txt > new.txt
should do the trick.
-Carlos
#13838 (just out of curiosity, another 13xxx :)
Tyson Scott @ 28/04/2010 1:19 -0300 dixit:
> 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
>
> _______________________________________________________________________
> Subscription information may be found at:
> http://www.groupstudy.com/list/CCIELab.html
>
>
>
>
>
>
>
-- Carlos G Mendioroz <tron_at_huapi.ba.ar> LW7 EQI Argentina Blogs and organic groups at http://www.ccie.netReceived on Wed Apr 28 2010 - 09:02:17 ART
This archive was generated by hypermail 2.2.0 : Sat May 01 2010 - 09:49:57 ART