You are not logged in.
Pages: 1
Hi. I would like towrite a script to search in a group of files for a pattern (in this case an specific word), and delete the lines containing that word.
Can anyone give me a hand?
thanks!
Athlon II X4 620 + Gigabyte 785GPM-UD2H + 4GB DDR3 + SSD OCZ Vertex2 60GB
Archlinux x86_64 + Openbox
Offline
If you are searching for something are you sure it is sed that you want to use? Could you give an example and provide a little more information into what you are trying to do?
Edit: I should have read the original post more carefully.
Last edited by dodo3773 (2012-01-09 19:33:21)
Offline
# delete lines matching pattern
sed '/pattern/d'
Edit:
[karol@black foo1]$ cat a
foo
bar
baz
[karol@black foo1]$ cat b
foo bar baz
bar
foo
baz
[karol@black foo1]$ cat c
foo
bar
foo
baz
[karol@black foo1]$ sed -i '/foo/d' $(find . -type f)
[karol@black foo1]$ cat a b c
bar
baz
bar
baz
bar
baz
Last edited by karol (2012-01-09 19:30:48)
Offline
I thought sed would be the easiest way to do it. Maybe perl would do it as well..
The idea would be something like this
for file in path
read every line.
if line matches pattern then delete line
Edit: Karol i just saw your editing. Thank you, i think that's what i needed.
Last edited by Viper_Scull (2012-01-09 19:42:17)
Athlon II X4 620 + Gigabyte 785GPM-UD2H + 4GB DDR3 + SSD OCZ Vertex2 60GB
Archlinux x86_64 + Openbox
Offline
Please don't use find like that, it's not always going to do what you want.
find . -type f -exec sed -i '/foo/d' {} +
Of course you're right, "my way" didn't even look right, but I've missed a typo when trying to do it the correct way. Thanks.
Need ... more ... coffee ...
Offline
Is the sintaxis of
find . -type f -exec sed -i '/foo/d' {} +
correct? It won't work on my pc like that.
What's the + for?
Last edited by Viper_Scull (2012-01-12 21:04:41)
Athlon II X4 620 + Gigabyte 785GPM-UD2H + 4GB DDR3 + SSD OCZ Vertex2 60GB
Archlinux x86_64 + Openbox
Offline
Yes, this line works.
What do you mean by "It won't work on my pc like that"? Are you getting any errors?
You should of course replace 'foo' with the phrase you want to remove. What's the word you want to get rid of?
Offline
Never mind. It's working now. I wasnt getting any error earlier just the propmt didnt show up like if it was expecting more arguments.
Thanks for your help.
I'm trying to understand the script.
what's the brackets and the + for?
Last edited by Viper_Scull (2012-01-13 00:21:50)
Athlon II X4 620 + Gigabyte 785GPM-UD2H + 4GB DDR3 + SSD OCZ Vertex2 60GB
Archlinux x86_64 + Openbox
Offline
what's the brackets and the + for?
Which part of 'man find' seems unclear? :-)
Offline
Pages: 1