Skip to content

Instantly share code, notes, and snippets.

@UniIsland
Last active October 10, 2023 11:05
Show Gist options
  • Save UniIsland/f2e2a92f1b30eeab06eadf5eb83baa56 to your computer and use it in GitHub Desktop.
Save UniIsland/f2e2a92f1b30eeab06eadf5eb83baa56 to your computer and use it in GitHub Desktop.
use xargs with bash function
#!/bin/bash
parse_and_echo() {
echo "\$1:$1 \$2:$2 \$3:$3 \$4:$4"
echo newline
}
export -f parse_and_echo
# `_' is placeholder for $0
cat ./xargs_with_function.txt | xargs -n 4 bash -c 'parse_and_echo $@' _
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment