SED on multiple quotation marks in BASH
I've inherited a lengthy text file that looks similar to:
"foo ""bar""; foo ""bar""" "foo ""bar""; foo ""bar""" "foo ""bar""; foo ""bar""" I would like it to become: foo "bar"; foo "bar" foo "bar"; foo "bar" foo "bar"; foo "bar" I'm most familiar with SED, but still a Linux / BASH newbie and can't quite figure this one out. I've covered Bruce Barnett's SED tutorial page, and working my way through the AWK tutorial as well, but after a few days I'm stumped I appreciate any help / advice anyone on here can offer. Thanks! |
Is tr ok?
Code:
cat t.t |tr -s [\"] |
And the sed solution:
Code:
sed -r 's/""+/"/g' file |
Thanks
Thanks to both of you for your quick responses. I actually hadn't previously come across the translate (tr) command until searching the message boards for this particular question (and chrism01's answer). I do have a couple short follow-up questions for clarification
Both of the codes (cat t.t |tr -s [\"] & sed -r 's/""+/"/g' file) worked to produce "foo "bar"; foo "bar" "foo "bar"; foo "bar" "foo "bar"; foo "bar" I need to remove the single quotation mark in front of foo at the beginning of each line. I was able to accomplish this with: sed 's/^" //' file which produced foo "bar"; foo "bar" foo "bar"; foo "bar" foo "bar"; foo "bar" But is there a way to put this all together in on short line, either 'tr' or 'sed?' Or is it just best to pipe the two commands together? Secondly, colucix can you explain what the + character is doing in the sed command? I have never seen that until now and haven't found it explained anywhere else? I certainly don't mind figuring it out for myself if anyone is willing to point me in the direction of a good external resource. Thanks again |
You can put two sed expressions together using two different -e options:
Code:
sed -r -e 's/""+/"/g' -e 's/^"//' file Code:
/""+/ A good tutorial on sed with a lot of regular expressions examples is http://www.grymoire.com/Unix/Sed.html. |
All times are GMT -5. The time now is 03:58 AM. |