regexp for multiline string
Posted: Thu 25 Mar 2010, 07:58
Hello I am new to reg. exp. in Linux. I try to write a rule for bash.
I have a string like this:
pattern="line 1: Hello, this line is just a report to user....
line2: this line is a separator between two lines
line 3: This line includes pattern. This line was generated in for command."
I would like to get two new string from it:
pattern, including line 3 - without \n - new line mark.
report, including line 1 - without \n - new line mark.
I tried some thing but no result.
Thanks for advice
edit - Solved
$(echo "$pattern" | sed -n '1p')
$(echo "$pattern" | sed -n '3p')
I have a string like this:
pattern="line 1: Hello, this line is just a report to user....
line2: this line is a separator between two lines
line 3: This line includes pattern. This line was generated in for command."
I would like to get two new string from it:
pattern, including line 3 - without \n - new line mark.
report, including line 1 - without \n - new line mark.
I tried some thing but no result.
Thanks for advice
edit - Solved
$(echo "$pattern" | sed -n '1p')
$(echo "$pattern" | sed -n '3p')