Tag Info

New answers tagged


Here is shell code (bash, ksh, or zsh) that may do what you want: image=clock.jpg size=$( identify -ping -format "%wx%h" "${image}" ) x_upb=${size%x*} y_upb=${size#*x} x_inc=10 y_inc=10 x_tile=100 y_tile=100 for ((x=0; x<x_upb; x+=x_inc)) do for ((y=0; y<y_upb; y+=y_inc)) do convert "${image}" -crop "${x_tile}x${y_tile}+${x}+${y}" ...


Why not use --pipe AND --pipepart with GNU Parallel? This eliminates the extra cat and starts direct reads from the file on disk: parallel --pipe --pipepart -a 2011.psv --block 500M ./carga_postgres.sh


Just for fun (and other shells) other variant: word=hello unset letter while [ ${#word} -gt 0 ] do rest=${word#?} letter[${#letter[*]}]=${word%$rest} word=$rest done And check for l in "${!letter[@]}" do echo "letter [$l] = ${letter[l]}" done will print letter [0] = h letter [1] = e letter [2] = l letter [3] = l letter [4] = o


Method 1: Oneliner: s="hello" for ((i=0;i<${#s};i++)); do result[$i]="${s:i:1}"; done echo ${result[@]} Expanded code: s="hello" # Original string. for ((i=0;i<${#s};i++)); do # For i=0; i<(length of s); i++ result[$i]="${s:i:1}" # result[i] is equal to the i th character of $s done # End of ...


To split string into array of characters, with null delimiter, you can: str='hello' arr=() i=0 while [ "$i" -lt "${#str}" ]; do arr+=(${str:$i:1}) i=$((i+1)) done printf '%s\n' "${arr[@]}" With delimiter other than null, you can: str='1,2,3,4,5' IFS=',' read -r -a arr <<<"$str" printf '%s\n' "${arr[@]}" or: set -f str='1,2,3,4,5' IFS=',' ...


s="hello" declare -a a for ((i=0; i<${#s}; i++)); do a[$i]="${s:$i:1}"; done declare -p a Output: declare -a a='([0]="h" [1]="e" [2]="l" [3]="l" [4]="o")' or s="hello" while read -n 1 c; do a+=($c); done <<< "$s" declare -p a Output: declare -a a='([0]="h" [1]="e" [2]="l" [3]="l" [4]="o")'


I think you can get away with using split's --filter=COMMAND. ... | split -b <SIZE> -d - part --filter=./split-filter where ./split-filter is something like #!/bin/bash set -e n="${FILE#part}" case $((10#$n%3)) in 0) dd bs=64K >"path1/$FILE" ;; 1) dd bs=64K >"path2/$FILE" ;; 2) dd bs=64K ...

Top 50 recent answers are included