Removing a line from file which is having specific pattern using shell script
I'm new to the shell scripting. can any one help in creating shell script for matching the content of the specific variable with file. it should remove that line from the file if line is containing same value as variable and keep the other content as it is.
i used grep -v for accomplishing the same. But grep will remove the pattern which is similar. For eg. Assume file "test" contain datas : aa ff if i used grep -v command for the pattern "a" to this file this will remove content "aa" from the file. I want the pattern only "a" should remove from the file, if it is existing. otherwise it should throw alert content not exists. |
Start by reading the grep man page carefully. It contains a good bit of information about how to match various text patterns. Then get on Google and find yourself a good regular expressions tutorial.
|
This will scan your file and if it finds a line with "aa" in there it will delete the whole line.
Code:
sed -i '/aa/d' filename |
Quote:
Also, if it's not homework, does it have to be a shell script? Perl has some nice pattern-matching capabilities..... |
I would also ask, is it a single 'a' on an entire line or an 'a' on its own anywhere on the line?
As the above have mentioned, the main issue is your regular expression being used is inadequate based on your requirements. |
Its Resolved......
Thnks David, Trist, TBone & Grail for your help... i have found my script worked after using grep -x -v option..
Thnks once again to you all.. |
All times are GMT -5. The time now is 01:10 PM. |