forcing everything python3, might end up with bugs

This commit is contained in:
Ville Rantanen
2021-04-09 13:01:04 +03:00
parent 72310083f6
commit 525c93a106
23 changed files with 276 additions and 243 deletions

View File

@@ -7,7 +7,7 @@ function c2t {
# Convert comma separated stream in to tab separated stream
# Usage: echo "foo,bar" | c2t
python -c 'import sys,csv
python3 -c 'import sys,csv
try:
csv.writer(sys.stdout, dialect=csv.excel_tab, lineterminator="\n").writerows(csv.reader(sys.stdin, dialect=csv.excel))
except IOError:
@@ -15,15 +15,15 @@ except IOError:
}
function header {
# Print only the first line of input
# Print only the first line of input
# Usage: header file.csv
# Usage: cat file.csv | header
# Usage: cat file.csv | header
head -n 1 "$@"
}
function noheader {
# Strip first row of input
# Strip first row of input
# Usage: noheader file.csv
# Usage: cat file.csv | noheader
@@ -33,7 +33,7 @@ function noheader {
function tsvecho {
# Echo with tab separated values, quoted
# Usage: tsvecho value1 value2 "some value" > header.csv
# Usage: echo value1 value2 | tsvecho
# Usage: echo value1 value2 | tsvecho
local HEAD
[[ -t 0 ]] && {
@@ -48,7 +48,7 @@ function tsvstrip {
# Strip tsv of quotes
# Usage: cat file.csv | tsvstrip
python -c 'import sys,csv
python3 -c 'import sys,csv
try:
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(csv.reader(sys.stdin, dialect=csv.excel_tab))
except IOError:
@@ -59,7 +59,7 @@ function tsvtranspose {
# Transpose a tsv file
# Usage: cat file.csv | tsvtranspose
python -c 'import sys,csv
python3 -c 'import sys,csv
try:
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(map(None,*csv.reader(sys.stdin, dialect=csv.excel_tab)))
except IOError:
@@ -71,9 +71,9 @@ function tsvhead {
# Usage: cat file | tsvhead -n 30
if [ -t 0 ]; then
python "${TSVDIR}"/lib/tsvhead "$@"
python3 "${TSVDIR}"/lib/tsvhead "$@"
else
cat - | python "${TSVDIR}"/lib/tsvhead "$@"
cat - | python3 "${TSVDIR}"/lib/tsvhead "$@"
fi
}
@@ -82,9 +82,9 @@ function tsvtail {
# Usage: cat file | tsvtail -n 30
if [ -t 0 ]; then
python "${TSVDIR}"/lib/tsvtail "$@"
python3 "${TSVDIR}"/lib/tsvtail "$@"
else
cat - | python "${TSVDIR}"/lib/tsvtail "$@"
cat - | python3 "${TSVDIR}"/lib/tsvtail "$@"
fi
}
@@ -94,7 +94,7 @@ function tsvcut {
# csvcut with tab-delimited dialect, see original script for options
# Usage: tsvcut -c Col1,Col3 input1.tsv
csvcut -t "$@" | c2t
}
@@ -102,7 +102,7 @@ function tsvformat {
# csvformat with tab-delimited dialect, see original script for options
# Usage: tsvformat -c Col2 -m searchString input1.tsv
csvformat -t -T "$@"
}
@@ -110,7 +110,7 @@ function tsvgrep {
# csvgrep with tab-delimited dialect, see original script for options
# Usage: tsvgrep -c Col2 -m searchString input1.tsv
csvgrep -t "$@" | c2t
}
@@ -118,7 +118,7 @@ function tsvjoin {
# csvjoin with tab-delimited dialect, see original script for options
# Usage: tsvjoin -c 1,1 input1.tsv input2.tsv
csvjoin -t "$@" | c2t
}
@@ -126,7 +126,7 @@ function tsvlook {
# csvlook with tab-delimited dialect, see original script for options
# Usage: tsvlook file1.tsv
csvlook -t "$@"
}
@@ -147,8 +147,8 @@ function tsvquery {
When defining a database with -d it is kept, and can be
inserted with more data later. Otherwise the DB is created in /tmp/
and deleted afterwards.
If not using name=data.tsv syntax, tables are named tsv1, tsv2...
Note: You have to give an SQL query. If you just want to
If not using name=data.tsv syntax, tables are named tsv1, tsv2...
Note: You have to give an SQL query. If you just want to
populate a database, add " " as an empty query.
'
return 0
@@ -167,7 +167,7 @@ function tsvquery {
# Add table with unique numbering
local OLDTBLS=$( sqlite3 "$DBTEMP" ".tables" )
local TBLNO=1
while :
while :
do echo $OLDTBLS | grep tsv$TBLNO > /dev/null || break
TBLNO=$(( $TBLNO + 1 ))
done
@@ -178,7 +178,7 @@ function tsvquery {
local FIL
TBL=$( echo ${!i} | sed 's,=.*,,' )
FIL=$( echo ${!i} | sed "s,^$TBL=,," )
[ -f "$FIL" ] && {
[ -f "$FIL" ] && {
cat "$FIL" | csvsql -t --db "sqlite:///$DBTEMP" --insert --table "$TBL"
} || {
echo File "${!i}" not found
@@ -191,7 +191,7 @@ function tsvquery {
local EC=$?
# remove DB if using temporary
[ -z "$j" ] && {
rm -f "$DBTEMP"
rm -f "$DBTEMP"
}
return $EC
}
@@ -200,7 +200,7 @@ function tsvsort {
# csvsort with tab-delimited dialect, see original script for options
# Usage: tsvsort -c Col3 input.tsv
csvsort -t "$@" | c2t
}
@@ -208,7 +208,7 @@ function tsvstack {
# csvstack with tab-delimited dialect, see original script for options
# Usage: tsvstack file1.tsv file2.tsv
csvstack -t "$@" | c2t
}
@@ -240,9 +240,9 @@ function tsvfold {
function tsvdims {
# Print dimensions of a TSV
# Usage: tsvdims file.txt
# Usage: cat file.txt | tsvdims
# Usage: cat file.txt | tsvdims
python -c 'import sys,csv
python3 -c 'import sys,csv
if sys.argv[1]=="":
input=sys.stdin
else: