summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Krag <jankrag@gmail.com>2014-01-09 22:25:45 +0100
committerHarel Ben-Attia <harelba@gmail.com>2014-01-15 16:42:37 -0500
commit8ec0cb91df19b18a2a232c5f1f012cd27737b703 (patch)
tree72ad06a4b204dc06802e825aec5de8b74a642f11
parent40e950941161653c875f8b23257703ed32858147 (diff)
Merging pull request of @JKrag (thanks!), with some minor changes, mainly changing the output delimiter letter and adding some comments1.1.3
-rw-r--r--.qrc2
-rw-r--r--README.markdown2
-rwxr-xr-xq17
3 files changed, 18 insertions, 3 deletions
diff --git a/.qrc b/.qrc
index cb90557..8606550 100644
--- a/.qrc
+++ b/.qrc
@@ -6,6 +6,7 @@
#
# Available options:
# * delimiter - escaped string (e.g. use \t for tab or \x20 for space)
+# * outputdelimiter - escaped string (e.g. use \t for tab or \x20 for space)
# * gzipped - boolean True or False
# * beautify - boolean True or False
# * header_skip - integer number of lines to skip at the beginning of the file
@@ -16,6 +17,7 @@
[options]
#delimiter: \t
+#output_delimiter: \t
#gzipped: False
#beautify: True
#header_skip: 0
diff --git a/README.markdown b/README.markdown
index a68cbde..12b76da 100644
--- a/README.markdown
+++ b/README.markdown
@@ -101,6 +101,7 @@ q can also get some runtime flags (Linux style, before the parameter). The follo
* `-z` - Means that the file is gzipped. This is detected automatically if the file extension if .gz, but can be useful when reading gzipped data from stdin (since there is no content based detection for gzip).
* `-H <N>` - Tells q to skip N header lines in the beginning of the file - Used naturally for skipping a header line. This can possibly be detected automatically in the future.
* `-d` - Column/field delimiter. If it exists, then splitting lines will be done using this delimiter. If not provided, **any whitespace** will be used as a delimiter.
+* `-D` - Column/field delimiter for output. If it exists, then the output will use this delimiter instead of the one used in input. Defaults to input delimiter if provided by `-d`, or space if not.
* `-b` - Beautify the output. If this flag exists, output will be aligned to the largest actual value of each column. **NOTE:** Use this only if needed, since it is slower and more CPU intensive.
* `-t` - Shorthand flag for a tab delimiter, one header line format (Same as `-d $'\t' -H 1` - The $ notation is required so Linux would escape the tab...)
* `-f <F>` - Output-formatting option. If you don't like the output formatting of a specific column, you can use python formatting in order to change the output format for that column. See below for details
@@ -151,3 +152,4 @@ This tool has been designed with general Linux/Unix design principles in mind. I
Any feedback/suggestions/complaints regarding this tool would be much appreciated. Contributions are most welcome as well, of course.
Harel Ben-Attia, harelba@gmail.com, @harelba on Twitter
+
diff --git a/q b/q
index 765e4e7..ed1039c 100755
--- a/q
+++ b/q
@@ -58,6 +58,7 @@ def get_option_with_default(p,option_type,option,default):
default_beautify = get_option_with_default(p,'boolean','beautify',False)
default_gzipped = get_option_with_default(p,'boolean','gzipped',False)
default_delimiter = get_option_with_default(p,'escaped_string','delimiter',None)
+default_output_delimiter = get_option_with_default(p,'escaped_string','output_delimiter',None)
default_header_skip = get_option_with_default(p,'int','header_skip',0)
default_formatting = get_option_with_default(p,'string','formatting',None)
default_encoding = get_option_with_default(p,'string','encoding','UTF-8')
@@ -88,6 +89,8 @@ parser.add_option("-z","--gzipped",dest="gzipped",default=default_gzipped,action
help="Data is gzipped. Useful for reading from stdin. For files, .gz means automatic gunzipping")
parser.add_option("-d","--delimiter",dest="delimiter",default=default_delimiter,
help="Field delimiter. If none specified, then standard whitespace is used as a delimiter")
+parser.add_option("-D","--output-delimiter",dest="output_delimiter",default=default_output_delimiter,
+ help="Field delimiter for output. If none specified, then the -d delimiter is used if present, or space if no delimiter is specified")
parser.add_option("-t","--tab-delimited-with-header",dest="tab_delimited_with_header",default=False,action="store_true",
help="Same as -d <tab> -H 1. Just a shorthand for handling standard tab delimited file with one header line at the beginning of the file")
parser.add_option("-H","--header-skip",dest="header_skip",default=default_header_skip,
@@ -506,10 +509,18 @@ m = sql_object.execute_and_fetch(db)
if options.beautify:
max_lengths = determine_max_col_lengths(m)
-if options.delimiter:
- output_delimiter = options.delimiter
+if options.output_delimiter:
+ # If output delimiter is specified, then we use it
+ output_delimiter = options.output_delimiter
else:
- output_delimiter = " "
+ # Otherwise,
+ if options.delimiter:
+ # if an input delimiter is specified, then we use it as the output as well
+ output_delimiter = options.delimiter
+ else:
+ # if no input delimiter is specified, then we use space as the default
+ # (since no input delimiter means any whitespace)
+ output_delimiter = " "
if options.formatting:
formatting_dict = dict([(x.split("=")[0],x.split("=")[1]) for x in options.formatting.split(",")])