extracting using sed
Given
Code:
Example is, "Hello", Code:
Hello |
What have you tried?
|
Hi Grail,
You did not mention the solution. |
sed 's/.*\(Hello\).*/\1/'
|
Quote:
a sed tutorial. |
Well actually its kinda hard for a beginner, but the point Grail is making is you should atleast put in some effort, then you'll find others more willing to help.
I tried doing it and found this works best(it took alot a reading an research lol, but glad I have alot a more useful knowledge now :) Quote:
|
Another point is that you need to explain your true goal more explicitly. Do you just need to match the exact string "Hello"? Do you need to match whatever is between the quote-marks on the line (and can there be more than one set of quotes)? Do you want the last word on the line, minus any quotes? Or what?
That's the real trick to regular expressions. You must first clearly define what differentiates the part you want to match from the parts you don't want. Only then you can structure your expression accordingly. Regex is one of the most useful tools you can learn in all computer use. It's well worth putting in some time to study them. Here are a couple of tutorials to start you with: http://mywiki.wooledge.org/RegularExpression http://www.grymoire.com/Unix/Regular.html |
And to prove David's point about how the same problem could be tackled differently depending on the requirement:
Code:
sed -r 's/^[^"]*"|".*$//g' |
All times are GMT -5. The time now is 04:33 AM. |