csv-utils 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/csv-change-eol +54 -0
- data/csv-utils.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d426e3be79ea7c3424c7778e2eb28ac750a55d0af374115021791506cfe933d
|
4
|
+
data.tar.gz: 00fec1a3995a515fca21f8032d40f9447cdbccfb53e7f22644982ff4c3d703a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d560c6b227162d297f396213cb26b277b437dc744a05f072f9f5716ea6920ff35dbedcdfcd544e4b5b8589f0e8e1322e79b5cdcb63d9d9e5f26019c141d77772
|
7
|
+
data.tar.gz: 7fd77c041baefdc87e4166781739bd97dc1183824414cb928c4a369adb972423d460f67562f848ac4373fb1c19cde9d962ee73a554590b0950d0bc9462e42b52
|
data/bin/csv-change-eol
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
def bold_string(str)
|
6
|
+
"\033[1m#{str}\033[0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
USAGE = "Usage: #{bold_string('csv-change-eol')} <csv_file> <end of line character sequence in hex>"
|
10
|
+
|
11
|
+
def exit_on_error(msg)
|
12
|
+
$stderr.print <<STR
|
13
|
+
Error: #{bold_string(msg)}
|
14
|
+
|
15
|
+
#{USAGE}
|
16
|
+
|
17
|
+
End of line example: '7C5E7C0A' is '|^|\\n'
|
18
|
+
- 0A is new line
|
19
|
+
- 0D is carriage return
|
20
|
+
|
21
|
+
Goto: #{bold_string('http://www.asciitable.com/')} for help with the character sequence
|
22
|
+
|
23
|
+
STR
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
csv_file = ARGV.shift || exit_on_error('no csv file specified')
|
28
|
+
eol_sequence = ARGV.shift || exit_on_error('no EOL character sequence specified')
|
29
|
+
|
30
|
+
exit_on_error("file #{csv_file} not found") unless File.exist?(csv_file)
|
31
|
+
exit_on_error("not a HEX sequece (#{eol_sequence})") unless eol_sequence =~ /\A[0-9a-f]+\z/i
|
32
|
+
exit_on_error("incorrect number of characters in (#{eol_sequence}), should be even") unless eol_sequence.size.even?
|
33
|
+
|
34
|
+
eol_sequence = [eol_sequence].pack('H*')
|
35
|
+
|
36
|
+
|
37
|
+
escaped_csv_file =
|
38
|
+
if csv_file =~ /\.csv$/i
|
39
|
+
csv_file.sub(/(\.csv)$/i, '.escaped-eol\1')
|
40
|
+
else
|
41
|
+
csv_file + '.escaped-eol'
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
File.open(escaped_csv_file, 'wb') do |out|
|
46
|
+
CSV.foreach(csv_file) do |row|
|
47
|
+
line = row.to_csv
|
48
|
+
line.rstrip!
|
49
|
+
line.concat(eol_sequence)
|
50
|
+
out.write line
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
puts escaped_csv_file
|
data/csv-utils.gemspec
CHANGED
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Tools for debugging malformed CSV files
|
14
14
|
email: dougyouch@gmail.com
|
15
15
|
executables:
|
16
|
+
- csv-change-eol
|
16
17
|
- csv-find-error
|
17
18
|
- csv-readline
|
18
19
|
extensions: []
|
@@ -21,6 +22,7 @@ files:
|
|
21
22
|
- ".gitignore"
|
22
23
|
- LICENSE
|
23
24
|
- README.md
|
25
|
+
- bin/csv-change-eol
|
24
26
|
- bin/csv-find-error
|
25
27
|
- bin/csv-readline
|
26
28
|
- csv-utils.gemspec
|
@@ -42,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
44
|
- !ruby/object:Gem::Version
|
43
45
|
version: '0'
|
44
46
|
requirements: []
|
45
|
-
rubygems_version: 3.0.
|
47
|
+
rubygems_version: 3.0.8
|
46
48
|
signing_key:
|
47
49
|
specification_version: 4
|
48
50
|
summary: CSV Utils
|