I have a csv file with fields like so:

"231444","344","some string","222"  

I have been trying, without success, to remove the double quotes from around the integers in the csv. I have tried a bit of sed, and attempted to awk/gawk but I am really having trouble with this one. Expected output would be:

231444,344,"some string",222  

There are no negative integers. Any help would be much appreciated, and thank you in advance.

有帮助吗?

解决方案

Just for a reference. This things are can be done using Perl's one liner as well.

linux:

perl -i.bak -p -e 's/"(\d+)"/$1/g' input.txt

For reference, Windows(single quote doesn't work):

perl -i.bak -p -e "s/\"(\d+)\"/$1/g" input.txt

其他提示

Your regex would be /"(\d+)"/g which should be replaced with \1.

Without knowing sed, I assume it'd be something like this (based on the Wikipedia example):

sed 's/"(\d+)"/\1/g' inputFileName > outputFileName

Regex 101 Demo

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top