Is it possible to do it in one liner?
I have an output like this:
"First line" - Description
" Second line" - Description
"Third line" - Description
" Fourth line" - Description
This input is generated automatically.
I want to replace the first occurrence of "
(quotation mark + space) with "
(quotation mark) for each line. If I apply the substitution globally, it will also change every occurrence of line" -
to line"-
, so I was wondering if it is possible to use a sed one liner to accomplish this.
I have tried using ^
like this
sed -r ':a;N;$!ba;s/(\^\" )/\"/g'
But it's not working, it doesn't replace anything. I tried
sed -r ':a;N;$!ba;s/(^|\" )/\"/g'
and it replaces all the occurrences. I've just started to use sed, so I don't really know if I'm doing something wrong.
What am I missing here?
sed
, but for portability and to avoid really weird errors, you should end a given command argument after a label (if you need them at all). E.g.,sed -e ':a' -e 'N;$!ba' -e 'whatever'