I have a file that looks like this:
asd 123 aaa wrqiqirw 123
123 itiewth 123 asno 123
123 132 123 123 123
boagii 123 asdnojaneoienton 123
Expected output is:
123
123
123
123
I will need to search for patterns via regex. Is there any way to implement such a thing?
man grepabout-o: "Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line" – SuibianP Mar 25 '22 at 10:13-odoes, but why is it relevant here? As you say, that would print all matches on separate lines, which is not what the OP wants (note that they show a file with 12 occurrences of123and a desired output with only 4). Also look at the answers already provided. – terdon Mar 25 '22 at 10:19grepdoes not print the first match by default, but all matches on the input line. Sorry if I misunderstood your comment. – SuibianP Mar 25 '22 at 10:33grep -oin this comment thread. All I did here was i) edit the question 5 years ago to fix some formatting issues and ii) leave a comment, also 5 years ago, asking the OP for more details since different patterns could affect the answer. I never mentioned-oorgrep. If you were to do this withgrep, it wouldn't be with a simplegrep -ofor the reason you mentioned. – terdon Mar 25 '22 at 10:45