tag:blogger.com,1999:blog-2807403883562053852.post3808424826033911952..comments2024-03-27T08:40:31.785-06:00Comments on Clayton Cramer.: Awk, Awk!Clayton Cramerhttp://www.blogger.com/profile/03258083387204776812noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-2807403883562053852.post-79741627375924444242019-05-23T12:20:07.219-06:002019-05-23T12:20:07.219-06:00What is blowing things up--as I'm sure you'...What is blowing things up--as I'm sure you've figured out--is that you've got commas embedded inside the fields. <br /><br />If you know Python, you can use the CSV module to simplify this for you--it (should) notice when a field begins ," and ends ", and treat what is in the middle as a single string. <br /><br />Otherwise you're going to need a simple state machine to find commas between " and turn them into something else, then turn them back. Billy Oblivionhttps://www.blogger.com/profile/16282343088921248885noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-70233029246429122902019-05-23T10:23:55.860-06:002019-05-23T10:23:55.860-06:001) sed?
2) "Some people, when faced with a U...1) sed?<br /><br />2) "Some people, when faced with a Unix problem, think 'aha! I know! I'll use sed!' ... now they have TWO problems."<br /><br />3) I would probably honestly write a parser.Sigivaldhttps://www.blogger.com/profile/16152366541957466049noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-42334812460639283162019-05-23T09:03:44.732-06:002019-05-23T09:03:44.732-06:00I have not tried this myself, but you might want t...I have not tried this myself, but you might want to check out this "advanced feature" of gawk: <a href="https://www.gnu.org/software/gawk/manual/html_node/Splitting-By-Content.html" rel="nofollow">Defining Fields by Content</a>.<br /><br />(Or use Text::CSV in Perl. But that's me.)Paul Sandhttps://www.blogger.com/profile/06175388613093409161noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-83409958159605458952019-05-22T23:25:37.435-06:002019-05-22T23:25:37.435-06:00There's no guaranteed solution with awk, but f...There's no guaranteed solution with awk, but for this specific case, it should be sufficient to replace all commas followed by a space with something unique, then run it through awk, then reverse the transformation:<br /><br />sed -e 's/, /__/g' | awk -F, '{print $1,$4,$5,$9}' | sed -e 's/__/, /g'<br /><br />-jJ Greelyhttps://www.blogger.com/profile/05547832508551235048noreply@blogger.com