Re: OT: Linux Shell Script

From: Carlos G Mendioroz <tron_at_huapi.ba.ar>
Date: Wed, 28 Apr 2010 08:29:11 -0300

Wow, that's cool. Just paste next line only if first line matches.
Then delete the pair if it was the right fit. I should start reading
the whole thread first...

-Carlos

Dan Shechter @ 28/04/2010 2:20 -0300 dixit:
> Hi Tyson,
>
> Try this:
>
> dans_at_dans-desktop:~/tmp/tyson$ cat a.txt | sed -e '/3/{
> N
> /3\n4/d
> }
> '
>
> HTH,
> Dan #13685 (RS/Sec/SP)
> Troubleshooting blog: http://dans-net.com
>
>
>
>
>
> On Wed, Apr 28, 2010 at 7:19 AM, Tyson Scott <tscott_at_ipexpert.com> wrote:
>
>> 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
>
>
> 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.net
Received on Wed Apr 28 2010 - 08:29:11 ART

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