some_command \
| grep -E 'some.*regex$' \
| sed -e 's/erase_text//g' \
| sed -e 's/erase_more//g' \
| awk '{ print $2 }' \
| cut -d ':' -f 1
I used to reach for Perl one-liners a lot, and still do sometimes when I need a gross regex that `sed -E` can't handle (See Perl Pie[1]), but Ruby has been making an appearance more and more often for handy one-liners. Roblog has a great post on using Ruby [2].If the script is complex enough and I'm willing to take a dependency on Ruby, that is usually where I turn. Where that line is does change from time to time. Ruby makes it super trivial to call shell commands and process them easily as well, which makes it easy to integrate into existing scripting [3].
Hopefully that answered your question :-)
[1] http://technosophos.com/2009/05/21/perl-pie-if-you-only-lear...
sed -e 's/erase_text//g; s/erase_more//g'
But I appreciate your example there is more for illustrative purposes rather than an actual pipeline you have in production.some_command | gawk ' /some.*regex$/ {gsub(erase_text,"");gsub(erase_more,"");split($2,a,":"); print (length(a[1]) ? a[1] : "STRING ERROR")}'
I like the pattern. Copied it to my notes to try next time I am grepping through logs.
I usually just string a few 'grep -v ignore_this' with pipes but then it ignores the whole line. But I can see how erasing some parts of the line would be very helpful sometimes.
some_command |
grep -E 'some.*regex$' |
sed -e 's/erase_text//g' |
sed -e 's/erase_more//g' |
awk '{ print $2 }' |
cut -d ':' -f 1