Tuesday, June 7, 2022

[SOLVED] Loop to remove inverted commas (") in a dataset in bash

Issue

I would like to find a way to use an iterative loop (for or while) to remove quotes (") from a dataset like the following:

",great britain,"America"

I know that there is the following way to remove them, which is actually more efficient, but it is important that it is an iterative statement in bash

sed -i -e 's/"//g' file.csv

Any idea?


Solution

You can use while read -r to read the lines. Use Parameter Expansion to remove the double quotes.

while read -r line ; do printf '%s\n' "${line//\"}" ; done < input


Answered By - choroba
Answer Checked By - Marilyn (WPSolving Volunteer)