Unix Shell - Cut (change in question)

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2007 > Cut (change in question)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Cut (change in question)
sant527@gmail.com

2007-11-28, 1:42 am

Sorry I have posted this before but I have a slight change in the
question.

I have an html file.The entire script is in one line only. The
following is the script.

<table><tbody><tr><td class="r">Chapter
1: ................................................. </td></tr></
tbody></table><p Hare Krishna ......................</p> <p Hare
Rama ......................</p>

where .............. is a variable text

In the above script I want to delete the text


<table><tbody><tr><td class="r">Chapter
1: ................................................. </td></tr></
tbody></table>


where ........ represents variable content.


I have 100 files with names 1.htm to 100.htm


How can i do this using unix commands rather than selecting the text
and deleting.


Thanks
Santhosh
Ed Morton

2007-11-29, 1:36 am



On 11/28/2007 12:23 AM, sant527@gmail.com wrote:
> Sorry I have posted this before but I have a slight change in the
> question.
>
> I have an html file.The entire script is in one line only. The
> following is the script.
>
> <table><tbody><tr><td class="r">Chapter
> 1: ................................................. </td></tr></
> tbody></table><p Hare Krishna ......................</p> <p Hare
> Rama ......................</p>
>
> where .............. is a variable text
>
> In the above script I want to delete the text
>
>
> <table><tbody><tr><td class="r">Chapter
> 1: ................................................. </td></tr></
> tbody></table>
>
>
> where ........ represents variable content.
>
>
> I have 100 files with names 1.htm to 100.htm
>
>
> How can i do this using unix commands rather than selecting the text
> and deleting.
>


Depending on whether not "<table>" or "</table>" can occur multiple times on a
line, this may be all you need:

for file in *.htm
do
sed 's:<table>.*</table>::' "$file" > tmp &&
mv tmp "$file"
done

Regards,

Ed.

sant527@gmail.com

2007-11-30, 1:47 am

On Nov 29, 8:49 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 11/28/2007 12:23 AM, sant...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> Depending on whether not "<table>" or "</table>" can occur multiple times on a
> line, this may be all you need:
>
> for file in *.htm
> do
> sed 's:<table>.*</table>::' "$file" > tmp &&
> mv tmp "$file"
> done
>
> Regards,
>
> Ed.



"<table>" or "</table>" can occur multiple times on a line then what
can be done
Ed Morton

2007-11-30, 1:47 am



On 11/29/2007 10:44 PM, sant527@gmail.com wrote:
> On Nov 29, 8:49 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>
>
>
> "<table>" or "</table>" can occur multiple times on a line then what
> can be done


Use all of the unique text you mentioned and replace the chain of periods with ".*":

sed 's:<table><tbody><tr><td class="r">Chapter 1:.*</td></tr></tbody></table>::'

If the text on either side of the ".*" can appear elsewhere on the same line,
then it's a harder problem that needs a different approach.

Ed.

sant527@gmail.com

2007-11-30, 1:47 am

On Nov 30, 9:57 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 11/29/2007 10:44 PM, sant...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Use all of the unique text you mentioned and replace the chain of periods with ".*":
>
> sed 's:<table><tbody><tr><td class="r">Chapter 1:.*</td></tr></tbody></table>::'
>
> If the text on either side of the ".*" can appear elsewhere on the same line,
> then it's a harder problem that needs a different approach.
>
> Ed.


Thank you.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com