update splitter for stdin
This commit is contained in:
@@ -6,30 +6,46 @@ _help() {
|
||||
echo ""
|
||||
echo "My default switches for split utility"
|
||||
echo "$CMD -b 500M FILE FILE."
|
||||
echo "if you want to split using stdin, use --stdin pattern"
|
||||
}
|
||||
_helpexit() {
|
||||
_help
|
||||
exit
|
||||
}
|
||||
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
[[ ${!i} = "-h" ]] && _helpexit
|
||||
[[ ${!i} = "--help" ]] && _helpexit
|
||||
done
|
||||
|
||||
args=( )
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
j=$(( i + 1 ))
|
||||
test -f "${!i}" && {
|
||||
file="${!i}"
|
||||
# file found, remove from arguments
|
||||
set -- "${@:1:i-1}" "${@:i+1}"
|
||||
}
|
||||
[[ "${!i}" = "-b" ]] && SIZE_SET=1
|
||||
[[ "${!i}" = "--stdin" ]] && {
|
||||
PATTERN="${!j}";
|
||||
set -- "${@:1:i-1}" "${@:i+2}"
|
||||
i=$(( i + 1 ));
|
||||
if [ -z "$PATTERN" ]; then echo must give pattern; exit 1; fi;
|
||||
|
||||
}
|
||||
done
|
||||
|
||||
[[ "$SIZE_SET" -eq 1 ]] || {
|
||||
size="-b 500M"
|
||||
}
|
||||
test -f "$file" || { echo "No such file"; exit 1; }
|
||||
set -x
|
||||
pv "$file" | $CMD $size "$@" - "$file".
|
||||
|
||||
if [[ -n "$PATTERN" ]]; then
|
||||
set -x
|
||||
cat - | pv | $CMD $size "$@" - "$PATTERN".
|
||||
exit
|
||||
else
|
||||
test -f "$file" || { echo "No such file"; exit 1; }
|
||||
set -x
|
||||
pv "$file" | $CMD $size "$@" - "$file".
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user