transpose: Wrapped with main function.

This commit is contained in:
Ole Tange 2018-04-28 21:17:34 +02:00
parent c9488299dc
commit 3e326d2ce5
5 changed files with 66 additions and 45 deletions

6
G/G
View file

@ -71,7 +71,11 @@ while(@ARGV) {
} }
} }
exec join"|", map { "grep ".join(" ", shell_quote(@$_)) } @cmd; if(@cmd) {
exec join"|", map { "grep ".join(" ", shell_quote(@$_)) } @cmd;
} else {
exec 'cat';
}
sub shell_quote { sub shell_quote {
# Input: # Input:

14
transpose/test.sh Normal file → Executable file
View file

@ -37,21 +37,21 @@ dotest() {
} }
. `which env_parallel.bash` . `which env_parallel.bash`
env_parallel -r <<EOF env_parallel -r <<'EOF'
dotest /tmp/table-3,1000000.csv
dotest /tmp/table-3,10000000.csv
dotest /tmp/table-1000,100000.csv
# Test --block 1 (problem with GNU Parallel < 20180422) # Test --block 1 (problem with GNU Parallel < 20180422)
dotest /tmp/table-3,1000.csv -b 1 dotest /tmp/table-3,1000.csv -b 1
dotest /tmp/table-3\|1000.csv
dotest /tmp/table-3,1000.csv dotest /tmp/table-3,1000.csv
dotest /tmp/table-3,10000.csv dotest /tmp/table-3,10000.csv
dotest /tmp/table-3,100000.csv dotest /tmp/table-3,100000.csv
dotest /tmp/table-3,1000000.csv
dotest /tmp/table-3,10000000.csv
dotest '/tmp/table-10\\t20.csv' dotest '/tmp/table-10\t20.csv'
dotest /tmp/table-10';'20.csv dotest /tmp/table-10';'20.csv
dotest '/tmp/table-100\\t200.csv' dotest '/tmp/table-100\t200.csv'
dotest /tmp/table-1,100.csv dotest /tmp/table-1,100.csv
dotest /tmp/table-10,1000.csv dotest /tmp/table-10,1000.csv
dotest /tmp/table-100,10000.csv dotest /tmp/table-100,10000.csv
dotest /tmp/table-1000,100000.csv
EOF EOF

View file

@ -262,10 +262,21 @@ file_to_paste_files() {
super_paste() { super_paste() {
# Like 'paste' up to 1000000 files # Like 'paste' up to 1000000 files
# More than 250000 files requires extra filehandles for GNU Parallel
# The files are read from stdin # The files are read from stdin
local sep local sep
local paste_files local paste_files
local fifo local fifo
other_commands() {
printf "\rSIGINT caught "
ls -l $paste_files
cat $paste_files | parallel "eval rm -f {} $fifo{0#}"
rm $paste_files
}
trap 'other_commands' SIGINT
sep="$1" sep="$1"
paste_files=`tempfile` paste_files=`tempfile`
# basename # basename
@ -305,8 +316,9 @@ usage() {
echo "Usage: $0 [-d delimiter] [-b blocksize]" 1>&2; exit 1; echo "Usage: $0 [-d delimiter] [-b blocksize]" 1>&2; exit 1;
} }
block_size=10M main() {
while getopts ":b:d:" o; do block_size=10M
while getopts ":b:d:" o; do
case "${o}" in case "${o}" in
d) d)
d="$(printf "${OPTARG}")" d="$(printf "${OPTARG}")"
@ -323,22 +335,25 @@ while getopts ":b:d:" o; do
usage usage
;; ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
if [ -z "${d}" ] ; then if [ -z "${d}" ] ; then
d="$(printf "\t")" d="$(printf "\t")"
fi fi
# Sep cannot be ' file="$@"
file="$@" first_lines=`tempfile`
first_lines=`tempfile` if [ -z "$file" ]; then
if [ -z "$file" ]; then
sep="$(stdin_detect_sep $first_lines)" sep="$(stdin_detect_sep $first_lines)"
(cat $first_lines; rm $first_lines; cat) | (cat $first_lines; rm $first_lines; cat) |
stdin_to_paste_files $block_size "$sep" | super_paste "$sep" stdin_to_paste_files $block_size "$sep" | super_paste "$sep"
else else
sep="$(stdin_detect_sep < "$file" $first_lines)" sep="$(stdin_detect_sep < "$file" $first_lines)"
rm $first_lines rm $first_lines
file_to_paste_files $block_size "$sep" "$file" | super_paste "$sep" file_to_paste_files $block_size "$sep" "$file" | super_paste "$sep"
fi fi
}
# Make sure the whole file is read before starting
main "$@"

View file

@ -7,7 +7,8 @@ INSTALLATION (create directories if they donot exist):
* Linux (current user): ~/.local/share/vlc/lua/extensions/ * Linux (current user): ~/.local/share/vlc/lua/extensions/
* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/ * Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
- Restart VLC. - Restart VLC.
- The extension can then be found in the menu View > Wastebasket. - The extension can then be found in the menu:
View > Move current playing file into wastebasket
]]-- ]]--
--[[ Extension description ]] --[[ Extension description ]]

View file

@ -69,13 +69,14 @@ $SIG{'CHLD'} = sub { exit; };
do { do {
# Sleep until there are matching files # Sleep until there are matching files
sleep(1); sleep(1);
@new = grep { not $before{$_} or $before{$_} > -M $_ } <*>; @new = (grep { -s $_ > 1000000 }
grep { not $before{$_} or $before{$_} > -M $_ } <*>);
} until @new; } until @new;
while(@new) { while(@new) {
# Mark as seen # Mark as seen
map { $before{$_} = -M $_ } @new; map { $before{$_} = -M $_ } @new;
# Run VLC on the matching files # Run VLC on the matching files
system("vlc",@new); system("vlc", map { $a=$_; s/.part//; $a,$_ } @new);
@new = grep { not $before{$_} or $before{$_} > -M $_ } <*>; @new = grep { not $before{$_} or $before{$_} > -M $_ } <*>;
} }