Aqui está uma maneira de fazê-lo awk(toda a saída, conforme feito pelo código em sua resposta).
Quando você acaba reprocessando a mesma entrada repetidamente, geralmente indica que outra abordagem pode ser melhor.
awké perfeito para processar entrada de texto como esta. awkprogramas são muito mais do que as coisas sejam feitas com sed, mas eles são muito mais fáceis de ler e você pode adicionar instruções de impressão para eles para fazer a depuração muito mais fácil.
Deixei minhas instruções de depuração em (comentadas). Você pode descomentá-los para ver como o script funciona.
Você precisa colocar o awkprograma em algum lugar e o lugar mais fácil em um único caso de uso como esse é colocar tudo em uma única cadeia de caracteres entre aspas na awklinha de comando.
Dessa forma, você não precisa armazená-lo em um arquivo separado ou em um arquivo temporário; portanto, não há gerenciamento de arquivos envolvido e o script permanecerá por si próprio.
Este programa parece longo, mas são quase todos os comentários, instruções de depuração e espaço em branco.
#!/bin/bash
## Whole awk program is one single quoted string
## on the awk command line
## so we don't need to put it in a separate file
## and so bash doesn't expand any of it
## Debugging statements were left in, but commented out
/usr/bin/cpuid | awk '
BEGIN { ## initialize variables - probably unnecessary
em = ""
ef = ""
fa = ""
mo = ""
si = ""
ps = ""
}
## get each value only once
## extended model is in field 4 starting at the third character
## of a line which contains "extended model"
/extended model/ && em == "" {
em = substr($4, 3)
##print "EM " em
}
## extended family is in field 4 starting at the third character
## of a line which contains "extended family"
/extended family/ && ef == "" {
ef = substr($4, 3)
##print "EF " ef
}
## family is in the last field, starting at the second character
## and is two characters shorter than the field "()"
## of a line which starts with "family"
## (so it does not match "extended family")
$1 == "family" && fa == "" {
##print NF " [" $NF "]"
##print "[" substr($NF, 2) "]"
l = length($NF) - 2
fa = substr($NF, 2, l)
##print "FA " fa
}
## model is in the third field, starting at the third character
## of a line which starts with "model"
## (so it does not match "extended model")
$1 == "model" && mo == "" {
mo = substr($3, 3)
##print "MO " mo
}
## stepping id is in field 4 starting at the third character
## of a line which contains "stepping id"
/stepping id/ && si == "" {
si = substr($4, 3)
##print "SI " si
}
## processor serial number is in field 4 starting at the third character
## of a line which contains "processor serial number:"
/processor serial number:/ && ps == "" {
ps = $4
##print "PS " ps
}
## Quit when we have all the values we need
em != "" && ef != "" && fa != "" && mo != "" && si != "" && ps != "" {
exit
}
END {
print em ef fa mo si " " ps
}
'