News for hackers. Stuff that matters.
Re:PowerShell is open sourced and is available on Linux by gpvos on Friday August 19, 2016 @06:29AM (#12319073)
Passing CSV around can be a useful middle ground, if you're using utilities that all do proper escaping and allow newlines in strings etc., such as csvkit.
Re:PowerShell is open sourced and is available on Linux by tonyedgecombe on Friday August 19, 2016 @06:43AM (#12319113)
What is proper escaping for CSV?
Re:PowerShell is open sourced and is available on Linux by gpvos on Friday August 19, 2016 @06:58AM (#12319170)
The problem is that not all tools agree on this one, but: lines are separated by newlines, items are separated by commas. An item can be quoted (and this must be done if it contains a newline, comma, or double quote) by surrounding them with double quotes. Inside such quoted items, double quotes can be escaped by doubling them.
Re:PowerShell is open sourced and is available on Linux by userbinator on Friday August 19, 2016 @06:54AM (#12319157)
RFC4180.
Re:PowerShell is open sourced and is available on Linux by qwertyuiop924 on Friday August 19, 2016 @12:09PM (#12321043)
DSV is the default format for many unix utils, and AWK and cut parse it easily.
Re:PowerShell is open sourced and is available on Linux by gpvos on Sunday August 21, 2016 @03:30PM (#12332340)
Yes, of course; that is one end of the "middle ground" I described. The problem is that in Unix, there is no common convention for how to escape the delimiter, so you cannot pass arbitrary strings. CSV can do this, with the proper tooling. Being able to pass around arbitrary strings is quite valuable, and although it is not quite the same as passing objects around, it has the advantage of still being human-readable text. That is why I called it a "useful middle ground" between Powershell and the delimiter-separated fields of Unix tools. However, you do need special tools such as csvkit, as Unix tools like awk, sort and cut cannot properly parse it.
Re:PowerShell is open sourced and is available on Linux by qwertyuiop924 on Monday August 22, 2016 @12:51PM (#12337615)
Oh, you can pass arbitrary strings, you just can't pass arbitrary strings as part of compound datastructures. The closest you can get is using null or some other weird character to separate lines ($RS='\0' in awk), and something similar for field separation (like -0 in find, which is $FS='\0' in awk). But \0 is only one special character, so you need another one.