I've got a bash
script that handles a bunch of input and then prints out prettily-formatted output. At the moment it's very modular -- it spawns tons of subshells and uses echo
, grep
, sort
, wc
, & sed
a lot, but I'm working on replacing the functionality of multiple chunks with larger awk
chunks, for better efficiency.
One struggle: I've been trying to figure out how to search input for specific strings, only printing the exact thing I'm searching for. I've been playing with awk's match
function but haven't had any success yet. Here's an example of one thing I'm trying to figure out how to integrate into a larger awk script:
$ egrep -o "pae|lm|vmx|svm|ht" /proc/cpuinfo | sort -u
ht
lm
pae
vmx
If I were to use awk to do the same thing, I'd want to end up with an array or variable containing each string I searched for that it found. The main problem as I see it is that each string I'm searching for might exist more than once in the input. Maybe I just need to buy an awk book... Any feedback welcome.