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 {
# Input:

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

@ -37,21 +37,21 @@ dotest() {
}
. `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)
dotest /tmp/table-3,1000.csv -b 1
dotest /tmp/table-3\|1000.csv
dotest /tmp/table-3,1000.csv
dotest /tmp/table-3,10000.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-100\\t200.csv'
dotest '/tmp/table-100\t200.csv'
dotest /tmp/table-1,100.csv
dotest /tmp/table-10,1000.csv
dotest /tmp/table-100,10000.csv
dotest /tmp/table-1000,100000.csv
EOF

View file

@ -262,10 +262,21 @@ file_to_paste_files() {
super_paste() {
# Like 'paste' up to 1000000 files
# More than 250000 files requires extra filehandles for GNU Parallel
# The files are read from stdin
local sep
local paste_files
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"
paste_files=`tempfile`
# basename
@ -305,8 +316,9 @@ usage() {
echo "Usage: $0 [-d delimiter] [-b blocksize]" 1>&2; exit 1;
}
block_size=10M
while getopts ":b:d:" o; do
main() {
block_size=10M
while getopts ":b:d:" o; do
case "${o}" in
d)
d="$(printf "${OPTARG}")"
@ -323,22 +335,25 @@ while getopts ":b:d:" o; do
usage
;;
esac
done
shift $((OPTIND-1))
done
shift $((OPTIND-1))
if [ -z "${d}" ] ; then
if [ -z "${d}" ] ; then
d="$(printf "\t")"
fi
fi
# Sep cannot be '
file="$@"
first_lines=`tempfile`
if [ -z "$file" ]; then
file="$@"
first_lines=`tempfile`
if [ -z "$file" ]; then
sep="$(stdin_detect_sep $first_lines)"
(cat $first_lines; rm $first_lines; cat) |
stdin_to_paste_files $block_size "$sep" | super_paste "$sep"
else
else
sep="$(stdin_detect_sep < "$file" $first_lines)"
rm $first_lines
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/
* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
- 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 ]]

View file

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