1

If I search with grep in a 30 gig database for some values it finds all of them in no time, if I run the same command with sed to replace those values it takes ages.

Why is grep so much faster than sed? and is there any application that can replace values with the same speed that grep finds them?

  • 1
    What are the exact commands you run? How big is the time difference (use time to find out)? Did you try to pipe the output of grep to sed? Does that change anything? – Lucas Apr 8 '16 at 10:54
  • I don't have stats handy now, will provide when I get a chance, but here is a comparative for now: davidlyness.com/post/… – Ulukai Apr 8 '16 at 11:23
  • 1
    "I don't have stats handy now"... sure but you could always post the actual commands you use there and some data sample... To answer part of your question: grep is optimized for search; sed's slower (though it can be pretty fast too) - there's no way to tell how much slower as your question is vague. – don_crissti Apr 8 '16 at 12:41
  • 1
    grep is only searching, sed is doing extra work (search and replace) - the latter is always going to take more time. If you are using sed -i (in-place edit) it's going to take even longer while sed writes its modified output to a temporary file and then replaces the original file with the temp file. – cas Apr 9 '16 at 1:07
  • A database, you say. Can't you use the database to update the values? – Kusalananda Feb 1 '17 at 11:02
1

In senario and text parsing they are different speed

For more info about what is diferrent between sed . Awk and grep see : https://davidlyness.com/post/the-functional-and-performance-differences-of-sed-awk-and-other-unix-parsing-utilities

  • Please include your answer here and not links. Links are not permanent and they waste people's time. – Jasser Mar 26 '18 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.