hi I am trying to edit a file through a shell script, but i am trying to edt it in a particular manner
here is a typical scenario i am facing
I have a file called script.txt withe following content :
*the owner of the* *trademark UNIX* *is The Open Group* *an industry standards* *consortium*.
Now i want to edit this file , but i want to edit this file in such a manner that after a given pattern i should be able to search an entire block-pattern , then delete that block-pattern .
for example suppose
after this given pattern */trademark UNIX/ * if exist then i want to delete the block-pattern /*is The Open Group*\n*an industry standards/*
??? any ideas
to append is pretty much simple with "sed " sed -i "/*trademark UNIX*/a*UNIX is great* \n*UNIX is awesome*" script.txt my file would then look something like this
*the owner of the* *trademark UNIX* *UNIX is great* *UNIX is awesome* *is The Open Group* *an industry standards* *consortium*
its is possible with sed and awk. can some one help me with my above query
Thanks
On Saturday 21 Jun 2008, Agnello George wrote:
hi I am trying to edit a file through a shell script, but i am trying to edt it in a particular manner
here is a typical scenario i am facing
I have a file called script.txt withe following content :
*the owner of the* *trademark UNIX* *is The Open Group* *an industry standards* *consortium*.
Now i want to edit this file , but i want to edit this file in such a manner that after a given pattern i should be able to search an entire block-pattern , then delete that block-pattern .
for example suppose
after this given pattern */trademark UNIX/ * if exist then i want to delete the block-pattern /*is The Open Group*\n*an industry standards/*
What exactly do you want to delete? The next two lines? The specific text ...Open group...industry standard...? Up to some other pattern?
-- Raju
after this given pattern */trademark UNIX/ * if exist then i want to delete the block-pattern /*is The Open Group*\n*an industry standards/*
What exactly do you want to delete? The next two lines? The specific text ...Open group...industry standard...? Up to some other pattern?
Yes i want to delete a specific text after a certain pattern is present , let me just re-explain, Suppose i have a given text file with the following content ** *the owner of the* *trademark UNIX* *is The Open Group* *an industry standards* *consortium*
then , if only /*trademark UNIX*/ is present then delete the the give specific text /*is The Open Group*\n*an industry standards*/
the end result of the file should look like this ** *the owner of the* *trademark UNIX* *consortium*
the pattern /*trademark UNIX/* should not be edited/deleted
Thanks again !!
--
सादर Agnello Dsouza www.linux-vashi.blogspot.com
On Saturday 21 Jun 2008, Agnello George wrote:
after this given pattern */trademark UNIX/ * if exist then i want to delete the block-pattern /*is The Open Group*\n*an industry standards/*
What exactly do you want to delete? The next two lines? The specific text ...Open group...industry standard...? Up to some other pattern?
Yes i want to delete a specific text after a certain pattern is present , let me just re-explain, Suppose i have a given text file with the following content ** *the owner of the* *trademark UNIX* *is The Open Group* *an industry standards* *consortium*
then , if only /*trademark UNIX*/ is present then delete the the give specific text /*is The Open Group*\n*an industry standards*/
the end result of the file should look like this ** *the owner of the* *trademark UNIX* *consortium*
the pattern /*trademark UNIX/* should not be edited/deleted
In Perl, something like this would do it:
perl -pi -e 'BEGIN{undef $/;} \ s/ALINE\nANOTHERLINE\nYETANOTHERLINE/ALINE/s;' /path/to/file
Add a g after the /s if you want to handle multiple matches. Add more s/.../.../gs; constructs if you want to handle multiple patterns.
Should be possible in both sed and awk too, but I'm too lazy to read the manuals right now.
Regards,
-- Raju
In Perl, something like this would do it:
perl -pi -e 'BEGIN{undef $/;} \ s/ALINE\nANOTHERLINE\nYETANOTHERLINE/ALINE/s;' /path/to/file
this is just a subsitution command , it just subsitutes ALIINE+ANOTHERLIN+YETANOTERLINE with ALINE
it could alo be done with sed : sed -i "s/ALINE\nANOTHERLINE\nYETANOTHERLINE/ALINE/g" script.txt
But what i really want to do is
if a certain pattern (A+B+C ) A B C is found then bellow pattern A delete pattern B and C