deleting a line containing the word
hello,
what would be the syntax to delete a line containg the word "word" from the file "file" i want to delete the whole line and not only the word... and i do not know the number of the line so thats not what im looking for |
Code:
sed -i '/word/d' filename Note also that this will remove all lines that contain the word. There's more trickery involved if you need to narrow it down to a single instance. Edit: Learn more about sed here: http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/sedfaq.html |
it doesnt work
i just tried that but it doesnt work...
heres what im doing: echo "Enter name: " read name; sed -i '/$name/d' register;; whats suppose to happen is that when i enter a certain name that is already there in the register... its suppose to be deleted WITH the number that is on the same line maybe this can help u help me |
Well, you didn't mention that this was for a script.
Your problem above is with shell quoting. Single quotes make everything inside them literal, so your '$' isn't read as a variable. You need to use double quotes here instead, which allows a few characters like this to still be interpreted. There are lots of good primers on bash scripting out there. Such as this one. http://tldp.org/LDP/Bash-Beginners-G...tml/index.html And their section on quoting: http://tldp.org/LDP/Bash-Beginners-G...ect_03_03.html |
thank you
i wanna kiss you so bad... too bad im married... ive spent atleast 3 hrs for this double quote.. thanks alot
|
I should say though that while that script will work, it's not very safe. As I mentioned, sed will remove every line with that text string in it. So if, for example you run the command:
Code:
sed "/Pete/d" file Code:
Pete Jones If you show us the exact format of the file, we may be able to make it safer using a proper regex. |
go to http://tldp.org
Get a copy of the Advanced Bash Scripting Guide and look up quoting |
All times are GMT -5. The time now is 01:21 AM. |