1

I have a file containing a long passage of text as follows

an excerpt from the file is

Mother cooked eggs for them, and they ate their breakfast hungrily. " It's lovely to be in the country! " said Jo,

whil i would like it to read

Mother cooked eggs for them, and they ate their breakfast hungrily. "It's lovely to be in the country!" said Jo,

is theres any way to achieve this using sed or any other cli tool

1

If it's only to replace once in each line, you can use sed 's/" \(.*\) "/"\1"/'. Otherwise, try sed 's/" \([^"]*\) "/"\1"/g'.

Example:

$ sed 's/" \(.*\) "/"\1"/' input_file_name
Mother cooked eggs for them, and they ate their breakfast hungrily. "It's lovely to be in the country!" said Jo,
3
  • the second example worked great for me thanks i appreciate it Dec 1 '16 at 22:56
  • But that won't work if the quotation spans several lines. Dec 2 '16 at 7:56
  • @MichaelVehrs Yes, sed is usually simply used for processing line by line.
    – fikr4n
    Dec 2 '16 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.