Article 5NKNR [SOLVED] [regex] Right syntax to parse semicolon-separated data?

[SOLVED] [regex] Right syntax to parse semicolon-separated data?

by
littlebigman
from LinuxQuestions.org on (#5NKNR)
Hello,

I can't figure out what regex to use with sed to parse a CSV file that uses the semicolon as separator: In both cases, the output contains all the columns instead of just 1, 3, and 5:

Code:input.txt:
FIELD1;FIELD2;FIELD3;FIELD4;FIELD5
123;Blah;456;Blah;Some text

sed -r 's@^(\d+);.+?;(\d+);.+?;(.+)$@\1\t\2\t\3@' < input.csv > output.csv

sed -r 's@^(\d+);[^;]+;(\d+);[^;]+;(.+)$@\1\t\2\t\3@' < input.csv > output.csvAny idea?

FWIW, I'm using sed (GNU sed) 4.4.

Thank you.latest?d=yIl2AUoC8zA latest?i=QzdIvAuoKH8:W8XOUmSigPI:F7zBnMy latest?i=QzdIvAuoKH8:W8XOUmSigPI:V_sGLiP latest?d=qj6IDK7rITs latest?i=QzdIvAuoKH8:W8XOUmSigPI:gIN9vFwQzdIvAuoKH8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments