-1

I have a specific requirement to replace double quotes in a purchase order(tab\pipe delimited) based on certain conditions. A sample record from the source file looks like this:

Record 1 : Item1|length 24.0" width 21"|Yes

Record 2 : Item2|"Length 25.0
           Width 26.0"|No

As shown above, the second record has a line feed in the description, and is enclosed by double quotes. I want to replace double quotes which come in all other fields, unbounded by double quotes, like in the description field of record 1.

My result would look like this:

Record 1 : Item1|length 24.0 width 21|Yes --> Double quotes removed

Record 2 : Item2|"Length 25.0
           Width 26.0"|No --> Double quotes left as such

How can I approach this problem using sed?

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • I matched the entire description field using this command : sed -e 's/\t[^\t]*"[^\t]*\t//g' file.txt. I'm looking for ways to remove just the double quotes in the matched pattern (I was testing with a tab delimited file) – Jishnu Nair Jan 26 '16 at 13:55

1 Answers1

0
$ sed 's/"\([^"]*\)"/\1/' file
Record 1 : Item1|length 24.0 width 21|Yes

Record 2 : Item2|"Length 25.0
           Width 26.0"|No

If that doesn't do what you want, edit your question to provide more comprehensive sample input and expected output.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • Thanks for the help, Ed. I could not directly use the code, but played around with capture groups and finally got what I wanted. This is the command I'm using : `sed -e 's/\(\t[^\t]*\)"\([^\t]*\t\)/\1 \2/g' file` – Jishnu Nair Jan 26 '16 at 17:20