Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
misc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
misc
Commits
e2939f47
Commit
e2939f47
authored
Feb 28, 2011
by
Kirill Smelkov
Committed by
Kirill Smelkov
May 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mdb-astextplain: выравниваем колонки по горизонтали
parent
560066f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
4 deletions
+70
-4
bin/csv-pprint
bin/csv-pprint
+63
-0
bin/mdb-astextplain
bin/mdb-astextplain
+7
-4
No files found.
bin/csv-pprint
0 → 100755
View file @
e2939f47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""pretty-print a csv input, aligning columns"""
import
sys
SEP
=
'|'
# XXX '|' separator hardcoded
ENC
=
'utf-8'
# XXX utf-8 encoding hardcoded
def
main
():
rows
=
[]
maxw
=
[]
# scan input, prettify fields, collect max coloumns width
for
line
in
sys
.
stdin
.
readlines
():
line
=
line
.
rstrip
()
# strip trailing '\n'
line
=
line
.
decode
(
ENC
)
# utf-8 -> unicode
fields
=
line
.
split
(
SEP
)
# numbers are pretty-printed
for
i
,
f
in
enumerate
(
fields
):
try
:
fields
[
i
]
=
int
(
f
)
continue
except
ValueError
:
pass
try
:
fields
[
i
]
=
float
(
f
)
except
ValueError
:
pass
if
len
(
fields
)
>
len
(
maxw
):
maxw
.
extend
(
[
0
]
*
(
len
(
fields
)
-
len
(
maxw
))
)
for
i
,
f
in
enumerate
(
fields
):
if
len
(
unicode
(
f
))
>
maxw
[
i
]:
maxw
[
i
]
=
len
(
unicode
(
f
))
rows
.
append
(
fields
)
# re-output rows, aligning them
for
fields
in
rows
:
line
=
''
for
f
,
w
in
zip
(
fields
,
maxw
):
# numbers are right-aligned, everything else - left
if
isinstance
(
f
,
(
int
,
long
,
float
)):
fstr
=
(
'%%%is'
%
w
)
%
f
else
:
fstr
=
(
'%%-%is'
%
w
)
%
f
line
=
SEP
.
join
((
line
,
fstr
))
# strip traling empty field, if any
line
=
line
.
rstrip
()
print
line
.
encode
(
ENC
)
if
__name__
==
'__main__'
:
main
()
bin/mdb-astextplain
View file @
e2939f47
...
...
@@ -12,11 +12,14 @@ while read ; do
tab
=
"
$REPLY
"
mdb-schema
-T
"
$tab
"
"
$mdbfile
"
|
grep
-v
'^--'
echo
"----8<----"
# header
mdb-export
-Q
-d
'|'
"
$mdbfile
"
"
$tab
"
|
\
(
# header
mdb-export
-Q
-d
'|'
"
$mdbfile
"
"
$tab
"
|
\
head
-1
# content sorted by first column
mdb-export
-Q
-d
'|'
-H
"
$mdbfile
"
"
$tab
"
|
\
# content sorted by first column
mdb-export
-Q
-d
'|'
-H
"
$mdbfile
"
"
$tab
"
|
\
sort
-t
'|'
-g
)
|
csv-pprint
echo
"----8<----"
done
<
$tabfile
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment