Input file (test): Desired output: What I have done: Question: How do you print the regex groups in sed (multiline)? Answer If you use sed like this: then it will print in different lines: But is this what you are trying to print? Or you want to print text in hrefs? Update 1: To get hrefs between well formed <a