You wouldn't really want to parse data in the shell itself, but to use a tool like awk
to do it for you.
awk -F '[[:blank:]|]+' '$1 > 20 { print $2 }' file
This instructs awk
to treat each line of the file as a set of fields delimited by any number of pipe-symbols or blanks (spaces or tabs). When the first field is greater than 20, the second field is printed.
Related:
If the second column contain blanks, then you may want to use [[:blank:]]*[|][[:blank:]]*
as the delimiter:
awk -F '[[:blank:]]*[|][[:blank:]]*' '$1 > 20 { print $2 }' file
The [|]
matches a literal pipe symbol, and may be replaced by \\|
(if you enjoy backslashes).
The following executes a script with each instance of the second column whose first column is greater than 20 as the command line argument:
awk -F '[[:blank:]]*[|][[:blank:]]*' '$1 > 20 { print $2 }' file |
xargs -I XX ./script.sh XX
With something like -P 4
as an option to xargs
, you can run multiple parallel instances of your script at once (four with -P 4
).