update splitter for stdin
This commit is contained in:
@@ -6,6 +6,7 @@ _help() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "My default switches for split utility"
|
echo "My default switches for split utility"
|
||||||
echo "$CMD -b 500M FILE FILE."
|
echo "$CMD -b 500M FILE FILE."
|
||||||
|
echo "if you want to split using stdin, use --stdin pattern"
|
||||||
}
|
}
|
||||||
_helpexit() {
|
_helpexit() {
|
||||||
_help
|
_help
|
||||||
@@ -19,17 +20,32 @@ done
|
|||||||
|
|
||||||
args=( )
|
args=( )
|
||||||
for (( i=1; i<=$#; i++ )); do
|
for (( i=1; i<=$#; i++ )); do
|
||||||
|
j=$(( i + 1 ))
|
||||||
test -f "${!i}" && {
|
test -f "${!i}" && {
|
||||||
file="${!i}"
|
file="${!i}"
|
||||||
# file found, remove from arguments
|
# file found, remove from arguments
|
||||||
set -- "${@:1:i-1}" "${@:i+1}"
|
set -- "${@:1:i-1}" "${@:i+1}"
|
||||||
}
|
}
|
||||||
[[ "${!i}" = "-b" ]] && SIZE_SET=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
|
done
|
||||||
|
|
||||||
[[ "$SIZE_SET" -eq 1 ]] || {
|
[[ "$SIZE_SET" -eq 1 ]] || {
|
||||||
size="-b 500M"
|
size="-b 500M"
|
||||||
}
|
}
|
||||||
test -f "$file" || { echo "No such file"; exit 1; }
|
|
||||||
set -x
|
if [[ -n "$PATTERN" ]]; then
|
||||||
pv "$file" | $CMD $size "$@" - "$file".
|
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