Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to find and replace some patterns in some files, but I need it to return 1 or something if a pattern is not found.

Can I do this with sed alone or do I need to check whether the pattern exists with another command?

Any suggestions?

share|improve this question
add comment

1 Answer

Check out this answer: How to check if sed has changed a file.

Its pretty much the same as you are asking, its suggesting you use awk or output to a different file and diff the two files.

share|improve this answer
7  
If using GNU sed, I would start with the least voted answers which use sed's q command to set the exit code. (Sadly q's exit code argument is not POSIX compliant.) –  manatwork Nov 15 '12 at 13:09
    
The least voted answer has changed. I think the answer @manatwork is referring to is stackoverflow.com/a/12144882/1033422 –  SHC Jan 7 at 8:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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