Let me make 2 suggestions for improving the legibility of sed scripts. (So often the juxtapostion of all the '/' & '\' characters make them look like perl, or /dev/random, or Chuck Norris sparring w/ David Carradine.)
1. Utilize ',' or anything you like for the separator. sed uses the next character after 's' as the separator & it can be anything you like -- i.e. find legible. Thus, "sed 's, ... , ... ,' " works fine.
2. When using a lot of characters -- {}() -- that need escaping in sed to become metacharacters, use the "r" option to make them meta from the beginning.
3. It is customary to single quote sed's commands.
Thus, that nice little sed command becomes:
Code:
sed -rne 's,^[^:]*(.{2}):.*$,\1,p'
& can be tested like this:
Code:
echo 'this is log file for deamon 1: which runs deamon program' |\
sed -rne 's,^[^:]*(.{2}):.*$,\1,p'