4 ms·
For the simplest uses, cut is more readable. If argument expansion is required, consider using read. That way the argument is given a name. Use "read a b c < x
by xorcist 7y ago
For the simplest uses, cut is more readable.
If argument expansion is required, consider using read. That way the argument is given a name. Use "read a b c < x" instead of "b=$(cat x | awk '{ print $2 }')".
Just remember to pipe to read with care, as the right hand part of a pipe is a subshell in which variables are local. So "read a b c < <(echo 1 2 3)" works, "echo 1 2 3 | read a b c" doesn't.
Another way to expand arguments is to simply define a shell function and use $2. Something like "process_line() { echo $2 }".
When you have to reach for something like awk, your script would probably improve by being mostly awk. In which case most people are probably looking at perl or python anyway. Even if awk is a nice language, the arrival of perl mostly killed it. It is not wrong to say perl was the next version of awk.