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 Answer 1

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 Commented Dec 1, 2016 at 22:56
  • But that won't work if the quotation spans several lines. Commented Dec 2, 2016 at 7:56
  • @MichaelVehrs Yes, sed is usually simply used for processing line by line.
    – fikr4n
    Commented Dec 2, 2016 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .