Skip to main content
14 events
when toggle format what by license comment
Aug 2, 2021 at 20:22 comment added Ed Morton FWIW I'd do this with awk -F, '$2 ~ /^(577|132)$/ { print > ($2 ".csv") }' file.csv.
Aug 2, 2021 at 20:18 comment added Kusalananda @EdMorton Ah, I see what I wrote back in 2019 now. Good, thanks for the comment!
Aug 2, 2021 at 20:17 comment added Ed Morton @Kusalananda Storing the file name in a variable as you suggested is fine too (and more useful if/when you also need to close() the output files), my only real point is that it's not a bug to fail given print > $2 ".cvs".
Aug 2, 2021 at 20:16 comment added Kusalananda @EdMorton Yeah, that would work too.
Aug 2, 2021 at 20:11 comment added Ed Morton @Kusalananda those awk implementations that fail given print > $2 ".cvs" aren't buggy. The meaning of print > $2 ".cvs" (or any other unparenthesized expression on the right side of output or input redirection) is undefined by POSIX so failing with an error is just as valid as trying to figure out what the user intended when they wrote that code. The POSIX-defined, portable way to write that code is print > ($2 ".cvs").
Jun 10, 2019 at 15:14 comment added Kusalananda There are buggy awk implementations that can't use print > $2 ".cvs". On those, you would have to first compute the filename, then do the print: fname = $2 ".cvs"; print > fname.
Jun 10, 2019 at 15:10 history edited Kusalananda CC BY-SA 4.0
Spring cleaning...
S Jun 10, 2019 at 9:48 history edited terdon CC BY-SA 4.0
fix small typing mistake
S Jun 10, 2019 at 9:48 history suggested microspino CC BY-SA 4.0
fix small typing mistake
Jun 10, 2019 at 9:48 review Suggested edits
S Jun 10, 2019 at 9:48
Feb 7, 2014 at 17:47 history edited terdon CC BY-SA 3.0
deleted 2 characters in body
Feb 7, 2014 at 17:35 history edited terdon CC BY-SA 3.0
added 4 characters in body
Feb 7, 2014 at 17:29 history edited terdon CC BY-SA 3.0
deleted 173 characters in body
Feb 7, 2014 at 16:49 history answered terdon CC BY-SA 3.0