Thursday, May 16, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 7055  / 1 Year ago, fri, may 5, 2023, 1:45:02

In a large (>1 gb) csv file I have something like



"34432", "name", "0", "very long description"


but instead of that I'd like to have



34432, "name", 0, "very long description".


I was looking at sed but this task is out of my scope.



Any advice how to achieve this?


More From » command-line

 Answers
5

Using perl:



perl -ne 's/"(d+)"/$1/g; print' file.csv > new_file.txt


All the work is done by s/"(d+)"/$1/g where




  • s/patternA/patternB/ is used to replace patternA by patternB

  • then perl looks for one or more digits d+ surrounded by double quotes.

  • the parenthesis around (d+) are used to capture the digit(s) and reuse them as a replacement pattern with perl special variable $1.


[#26137] Friday, May 5, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diffeah

Total Points: 78
Total Questions: 130
Total Answers: 98

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;