Here's the regex that will match everything from the pattern until a newline is found.
Say you want to remove everything after "here" from this sample file.
code here where?
code here right here!
code here look every where.
Used regex
s/here.*//
Explanation:
.*
dot matches any character including spaces, numbers, alphabets but not new line.
asterisk matches any number of occurrences of a character
s/here.*/meow/ will result in
code meow
code meow
code meow
Thanks a lot! I was looking for something like that in 0'Reilly book about sed, that famous one, but could not find what I really needed. A search in the internet got to this blog, that I will follow from now one.
ReplyDelete