The “cut” command is great for splitting a string on a single character and extracting specific fields. But it will not work with multi-character delimiters. Here’s a simple replacement using awk that will get the job done. Let’s assume you have a string like:
1 |
arg1=a&arg2=b&arg3=c |
We could extract the value of “arg3” using cut with:
1 |
echo "arg1=a&arg2=b&arg3=c" | cut -f 3 -d "&" | cut -f 2 -d '=' |
But this assumes that there are always the same number of proceeding args:
Now lets do it with awk:
1 |
awk -F'arg3=' '{print $2}' |
But what if the args are in different order? The we can use sed:
1 |
sed 's/\(.*\)arg3=\(.*\)/\2/g' |