0

Search pattern examples

"0:4.10.5-5.el7"
"0:0.7.7-13.20120626.ov7"
"6:4.14.8-6.po7_3"
  1. How to search and print all occurrences like above patterns where the first number can be any number ranging from 0-9 separated by ":" trailing with any number or alphabet ranging from a-z separated by . or. in vi editor ?

I could search the occurrences of all the patterns starting with any number [0-9] separated by ":" using

:%s/[0-9]\+\:
  1. how to remove all the occurrences till end of line of each occurrence
5
  • This worked for removing all occurrences of any wild character trailing : till end of line :%s/[0-9]:.*//g Mar 22, 2019 at 15:34
  • To replace beginning of each line in the entire file with a specific pattern ==> :%s/^/stringtoreplace/ Mar 22, 2019 at 15:40
  • place all pattern test cases on each line enclosed with ```. And add what you want the result to be.
    – 3N4N
    Mar 22, 2019 at 16:21
  • So 1) do you want to match all your examples or what you described as test? If the latter you can use /\d:[0-9a-z\.]\+ if you want to match your examples you'll need to add _- to [0-9a-z\.]. 2) Your second question is not clear: do you want to remove everything after the : in this case you can use :%s/\d\+:\zs[0-9a-z\.]\+//. If you want to remove all the lines matching the previous pattern you can use a global command like :g/\d\+:[0-9a-z-\.]\+/d. Maybe try to clarify your question so that we can answer it precisely.
    – statox
    Mar 22, 2019 at 17:18
  • And 3) If what you said in your comments is what you were looking for, please write an answer with proper formatting.
    – statox
    Mar 22, 2019 at 17:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.