Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added 296 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

You would have to iterate over the fields and replace the quote character in each. Stéphane shows how to do this using awk in their answer.

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, the put expression iterates over all fields and removes the first character from them if it is a single quote (047 in octal).


Another approach with Miller which uses apply() to apply a function that deletes an initial single quote from a field. The function is applied to each field in each record.

$ mlr --csv --fs pipe -N put '$* = apply($*, func(k,v) { return { k: sub(v, "^\047", "") } })' file
foo|012|that's nice|bar

You would have to iterate over the fields and replace the quote character in each. Stéphane shows how to do this using awk in their answer.

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, the put expression iterates over all fields and removes the first character from them if it is a single quote (047 in octal).

You would have to iterate over the fields and replace the quote character in each. Stéphane shows how to do this using awk in their answer.

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, the put expression iterates over all fields and removes the first character from them if it is a single quote (047 in octal).


Another approach with Miller which uses apply() to apply a function that deletes an initial single quote from a field. The function is applied to each field in each record.

$ mlr --csv --fs pipe -N put '$* = apply($*, func(k,v) { return { k: sub(v, "^\047", "") } })' file
foo|012|that's nice|bar
added 72 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

You would have to iterate over the fields and replace the quote character in each. Stéphane shows how to do this using awk in their answer.

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr)Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, itthe put expression iterates over all the fields and removes the first character from eachthem if it is a single quote (047 in octal).

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, it iterates over all the fields and removes the first character from each if it is a single quote (047 in octal).

You would have to iterate over the fields and replace the quote character in each. Stéphane shows how to do this using awk in their answer.

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, the put expression iterates over all fields and removes the first character from them if it is a single quote (047 in octal).

Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

$ mlr --csv --fs pipe -N put 'for (k,v in $*) { $[k] = sub(v, "^\047", "") }' file
foo|012|that's nice|bar

This uses Miller (mlr) to read the input as a header-less CSV data set (with pipes as field delimiters). For each record, it iterates over all the fields and removes the first character from each if it is a single quote (047 in octal).