When both sed and awk will do, which one to chose?
by arifd86 from LinuxQuestions.org on (#5DCB7)
I have the inclination that sed is the lighterweight of the two and thus should be used.
But my sed command uses a wildcard, whereas awk doesn't need to. (However, i don't know if behind the scenes they're both doing regex and thus the search pattern in itself is of equal speed)
here's what I'm doing: (want to return only the number)
Code:echo ' index: 56' | sed 's/.* index: //'Code:echo ' index: 56' | awk '/index:/{print $2}'edit prepending with time, awk seems to consistently beat sed by 0.001s


But my sed command uses a wildcard, whereas awk doesn't need to. (However, i don't know if behind the scenes they're both doing regex and thus the search pattern in itself is of equal speed)
here's what I'm doing: (want to return only the number)
Code:echo ' index: 56' | sed 's/.* index: //'Code:echo ' index: 56' | awk '/index:/{print $2}'edit prepending with time, awk seems to consistently beat sed by 0.001s